Skip to content

Instantly share code, notes, and snippets.

@seldo
Created May 9, 2019 20:07
Show Gist options
  • Save seldo/90acf67dda6db453a5e19fa93a707f80 to your computer and use it in GitHub Desktop.
Save seldo/90acf67dda6db453a5e19fa93a707f80 to your computer and use it in GitHub Desktop.
const fs = require('fs');
const readline = require('readline');
async function processLineByLine() {
const fileStream = fs.createReadStream('input.txt');
const rl = readline.createInterface({
input: fileStream,
crlfDelay: Infinity
});
// Note: we use the crlfDelay option to recognize all instances of CR LF
// ('\r\n') in input.txt as a single line break.
for await (const line of rl) {
// Each line in input.txt will be successively available here as `line`.
console.log(`Line from file: ${line}`);
}
}
processLineByLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment