Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 397 Bytes

section9.1.md

File metadata and controls

19 lines (15 loc) · 397 Bytes

Section 9.1: Line-by-line file reading

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

const rl = readline.createInterface({
  input: fs.createReadStream('text.txt')
});

// Each new line emits an event - every time the stream receives \r, \n, or \r\n
rl.on('line', (line) => {
  console.log(line);
});

rl.on('close', () => {
  console.log('Done reading file');
});