Hi everyone,I'm a newbie in nodejs and express, so i'm trying to generate one CSV file reading a content of one log file, something like this:
var csv;var instream = fs.createReadStream(pathLog+req.params.file);var outstream = new stream;outstream.readable = true;outstream.writable = true;var rl = readline.createInterface({input: instream,output: outstream,terminal: false});rl.on('line', function(lin,csv) {
var csv; // this one is shadowing the one from the parent scope
if(req.params.id != ''){var re = new RegExp(req.params.id, 'i');if(lin.match(re) != null){var string = lin.substring(143,lin.length);csv += ','+string;}}});res.set('Content-Type', 'application/octet-stream');
console.log(csv); // You need to wait for the readline close event before logging out
Willem,Thank you for help, sorry but I'm beginner and still do not understand some things, like how I'll wait for the event line finish and so run the console.log?I changed the code to this, its correct?var csv;var instream = fs.createReadStream(pathLog+req.params.file);var outstream = new stream;outstream.readable = true;outstream.writable = true;var rl = readline.createInterface({input: instream,output: outstream,terminal: false});rl.on('line', function(lin) {var re = new RegExp(req.params.id, 'i');if(lin.match(re) != null){var string = lin.substring(143,lin.length);
csv += ','+string;}}});res.set('Content-Type', 'application/octet-stream');
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/qQ6prse3r0c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.