Skip to content

Instantly share code, notes, and snippets.

@AkatQuas
Last active October 28, 2019 01:56
Show Gist options
  • Save AkatQuas/734bd68c75be5e052a4788a1290629f2 to your computer and use it in GitHub Desktop.
Save AkatQuas/734bd68c75be5e052a4788a1290629f2 to your computer and use it in GitHub Desktop.
simple lines for read from/print to terminal
process.stdin.resume();
process.stdin.setEncoding('ascii'); // 'utf-8' also supported
let _input = "";
process.stdin.on('data', function (data) {
_input += data;
});
process.stdin.on('end', function () {
process.stdout.write(_input);
});
/*
// usage example
// you need to create a readstream which has and 'end' signal
// in the terminal
$ cat <file> | node io-with-terminal.js
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment