Skip to content

Instantly share code, notes, and snippets.

@MelodicCrypter
Created August 19, 2019 06:26
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 MelodicCrypter/0c3dee1b14330f959e3e313d53ad1143 to your computer and use it in GitHub Desktop.
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.
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