The first problem is that you are not waiting for the stream to finish. 
Your console.log is called immediately.
You're also shadowing the csv variable in your line event, so you need to 
remove the local csv variable there as well.


On Friday, January 17, 2014 1:23:26 PM UTC+1, Felipe Silveira wrote:
>
> 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*
>
>
> The real problem is, I declared the variable csv and in the event line I'm 
> incrementing that but in the console.log return undefined.
>
> Thank you!
>
>
> *Att,*
>
> *Felipe Silveira Mendes*Site <http://felipems.com.br> - 
> Twitter<https://twitter.com/felipesmendes>- 
> Blog <http://felipems.com.br/blog>
> *Web Developer*
> *(31) 8370-9090 (Claro)*
> *(31) 9433-9310 (Tim)*
> *[email protected] <javascript:>*
>
>
>  

-- 
-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to