Created
January 19, 2020 18:39
-
-
Save debonx/9034807714731454d40fd8541f5b9160 to your computer and use it in GitHub Desktop.
Node: Writable stream, to get data from file and write on another.
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 readline = require('readline'); | |
const fs = require('fs'); | |
// Create interface with a reading stream | |
const myInterface = readline.createInterface({ | |
input: fs.createReadStream('shoppingList.txt') | |
}); | |
// Create a write stream to custom file | |
const fileStream = fs.createWriteStream('shoppingResults.txt.'); | |
// Design callback to output in writable file | |
const transformData = (line) => { | |
fileStream.write(`They were out of: ${line}\n`); | |
} | |
// Output on each line read | |
myInterface.on('line', transformData); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment