Friday 21 April 2017

how to read next line in node.js

i'm using this snippet to read lines from a file in node.js:

var lineReader = require('line-reader');

lineReader.open('foo.txt', function(err, reader) {
  if (err) throw err;
  while (reader.hasNextLine()) {
    reader.nextLine(function(err, line) {
        console.log(line);
    });
  }
});

I'm wondering if is it possible to know the nextLine, for example, if the file is so written:

line1
line2

i want to print line2.

how i can achieve this?

thanks in advance.



via OiRc

No comments:

Post a Comment