Answers for "node js read file stream line by line"

0

node js read file stream line by line

const readline = require('readline');
const fs = require('fs');

// create instance of readline
// each instance is associated with single input stream
let rl = readline.createInterface({
    input: fs.createReadStream('products.txt')
});

let line_no = 0;

// event is emitted after each line
rl.on('line', function(line) {
    line_no++;
    console.log(line);
});

// end
rl.on('close', function(line) {
    console.log('Total lines : ' + line_no);
});
Posted by: Guest on March-04-2021

Code answers related to "node js read file stream line by line"

Code answers related to "Javascript"

Browse Popular Code Answers by Language