Skip to content

Instantly share code, notes, and snippets.

@gartenfeld
Created November 26, 2017 12:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gartenfeld/d7f12167c4fc4aebf3e2132e0208b8f9 to your computer and use it in GitHub Desktop.
Save gartenfeld/d7f12167c4fc4aebf3e2132e0208b8f9 to your computer and use it in GitHub Desktop.
Read a file one line at a time
const fs = require('fs');
const path = require('path');
const readline = require('readline');
const FILE_PATH = path.resolve(__dirname, '../data/ingest_test.txt');
const stream = fs.createReadStream(FILE_PATH);
const interface = readline.createInterface({ input: stream });
interface.on('line', processLine);
interface.on('close', () => console.log("\nDone!"));
function processLine(line) {
process.stdout.write(line.length + ' ');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment