Without 3rd party extensions! What you need are the fs
, readline
and stream
module.
var fs = require('fs'),
readline = require('readline'),
stream = require('stream');
var instream = fs.createReadStream('your/file'),
outstream = new stream,
rl = readline.createInterface(instream, outstream);
rl.on('line', function(line) {
// process line here
});
rl.on('close', function() {
// do something on finish here
});
The solution comes from here