Skip to content

Instantly share code, notes, and snippets.

@nicky-zs
Created December 19, 2013 02:47
Show Gist options
  • Save nicky-zs/8033566 to your computer and use it in GitHub Desktop.
Save nicky-zs/8033566 to your computer and use it in GitHub Desktop.
The readline functionality is not very well supported in nodejs for it's api level is unstable as well as it is treated for tty use first. Here is a simple segment to readline from stdin. If you want to readline from a file, either changing the code with fs.createReadStream or just redirecting input from bash can do.
var readline = require('readline');
function main() {
readline.createInterface({
input: process.stdin,
terminal: false,
}).on('line', function(line) {
console.log(line);
});
}
if (require.main === module) {
main();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment