Created
August 19, 2019 06:26
-
-
Save MelodicCrypter/0c3dee1b14330f959e3e313d53ad1143 to your computer and use it in GitHub Desktop.
A NodeJS sample using Pipe that automatically logs whatever the user types in the console.
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 { createWriteStream } = require('fs'); | |
const writeStream = createWriteStream('./file-test.txt'); | |
// using stdin, stream and pipe, this will automatically log all the text you will type | |
process.stdin.pipe(writeStream); | |
process.stdin.on('data', (data) => { | |
if (data.toString().toLowerCase().trim() === 'exit>this') { | |
process.exit(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment