Created
November 26, 2017 12:45
-
-
Save gartenfeld/d7f12167c4fc4aebf3e2132e0208b8f9 to your computer and use it in GitHub Desktop.
Read a file one line at a time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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