Created
November 18, 2015 20:01
-
-
Save andreruffert/f4d0dd7385e2735eca93 to your computer and use it in GitHub Desktop.
Node.js read file line by line and transform it
This file contains hidden or 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 readline = require('readline'); | |
const readFile = readline.createInterface({ | |
input: fs.createReadStream('file.in'), | |
output: fs.createWriteStream('file.out'), | |
terminal: false | |
}); | |
readFile | |
.on('line', transform) | |
.on('close', function() { | |
console.log(`Created "${this.output.path}"`); | |
}); | |
function transform(line) { | |
this.output.write(`modified ${line}\n`); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment