diwesh
diwesh

Reputation: 294

Node.js code for parsing file in cloudant

I loaded a log file ( text format) in the Cloudant. I am not sure if any node.js code is available to parse files or do I need to write my own parser ?

Upvotes: 0

Views: 877

Answers (3)

CharlesL
CharlesL

Reputation: 942

This is a good tutorial on how to access your documents in Cloudant from a node.js application in Bluemix.

https://www.ibm.com/developerworks/community/blogs/theTechTrek/entry/a_cloud_medley_with_ibm_bluemix_cloudant_db_and_node_js?lang=en

require('http').createServer(function(req, res) {
//Set up the DB connection
if (process.env.VCAP_SERVICES) {
// Running on Bluemix. Parse for  the port and host that we've been assigned.
var env = JSON.parse(process.env.VCAP_SERVICES);
var host = process.env.VCAP_APP_HOST;
var port = process.env.VCAP_APP_PORT;
....
}
....
// Perform CRUD operations through REST APIs
// Insert document
if(req.method == 'POST') {
insert_records(req,res);
}
// List documents
else if(req.method == 'GET') {
list_records(req,res);
}
// Update a document
else if(req.method == 'PUT') {
update_records(req,res);
}
// Delete a document
else if(req.method == 'DELETE') {
delete_record(req,res);
}
}).listen(port, host);

Upvotes: 2

tonyerwin
tonyerwin

Reputation: 66

If you are inserting a JSON document into the Cloudant DB, then you shouldn't have to do any special parsing when you get it out of the DB.

Are you also wondering how to retrieve it? Without knowing more about what library you're using or how you want to retrieve the document (whether by doc_id, by querying using an index, etc.), it's hard to offer much guidance. But, if you have the document's id and you're using the Cloudant Node.js Client, then you can use the db.get function.

Upvotes: 1

tonyerwin
tonyerwin

Reputation: 66

I think I need a little more information to help. So, a couple questions for you:

  • What format is the log's text in? For example, JSON? XML? Something else?
  • How did you add the text to Cloudant to start with? Are you using any particular module to interact with Cloudant? (For example, I use the Cloudant Node.js Client.)

Upvotes: 0

Related Questions