1const fs = require('fs');
2const readline = require('readline');
3
4async function processLineByLine() {
5 const fileStream = fs.createReadStream('input.txt');
6
7 const rl = readline.createInterface({
8 input: fileStream,
9 crlfDelay: Infinity
10 });
11 // Note: we use the crlfDelay option to recognize all instances of CR LF
12 // ('\r\n') in input.txt as a single line break.
13
14 for await (const line of rl) {
15 // Each line in input.txt will be successively available here as `line`.
16 console.log(`Line from file: ${line}`);
17 }
18}
19
20processLineByLine();
21
1const readline = require('readline');
2
3const readInterface = readline.createInterface({
4 input: fs.createReadStream('name.txt'),
5 output: process.stdout,
6 console: false
7 });
8
9 for await (const line of readInterface) {
10 console.log(line);
11 }
12//or
13readInterface.on('line', function(line) {
14 console.log(line);
15});