Last active
October 28, 2019 01:56
-
-
Save AkatQuas/734bd68c75be5e052a4788a1290629f2 to your computer and use it in GitHub Desktop.
simple lines for read from/print to terminal
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
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