read line by nodejs code example
Example 1: node.js read text file line by line
const readline = require('readline');
const readInterface = readline.createInterface({
input: fs.createReadStream('name.txt'),
output: process.stdout,
console: false
});
for await (const line of readInterface) {
console.log(line);
}
readInterface.on('line', function(line) {
console.log(line);
});
Example 2: File line by line reader Node js
var lineReader = require('line-reader');
lineReader.eachLine('file.txt', function(line, last) {
console.log(line);
if(last){
}
});