straming in node using createInterface() of readLine module and also it is an event object . Also has .on()

PHOTO EMBED

Tue Aug 31 2021 01:44:52 GMT+0000 (UTC)

Saved by @faisals #node #filesystem

const readline = require('readline');
const fs = require('fs');
 
const myInterface = readline.createInterface({
  input: fs.createReadStream('text.txt')
});
 
myInterface.on('line', (fileLine) => {
  console.log(`The line read: ${fileLine}`);
});
content_copyCOPY

read files line-by-line, we can use the .createInterface() method from the readline core module. .createInterface() returns an EventEmitter set up to emit 'line' events: