The Node.js Documentation offers a very elegant example using the Readline module.
Example: Read File Stream Line-by-Line
const fs = require('fs');
const readline = require('readline');
const rl = readline.createInterface({
input: fs.createReadStream('sample.txt'),
crlfDelay: Infinity
});
rl.on('line', (line) => {
console.log(`Line from file: ${line}`);
});
Note: we use the crlfDelay option to recognize all instances of CR LF ('\r\n') as a single line break.