Skip to content

Instantly share code, notes, and snippets.

@kingcc
Last active March 23, 2017 05:30
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 kingcc/76a2827db70f6820b853033092ba693e to your computer and use it in GitHub Desktop.
Save kingcc/76a2827db70f6820b853033092ba693e to your computer and use it in GitHub Desktop.
nodeJS read muti-lines datas from console.
/**
* nodeJS read muti-lines datas from console.
* @Author kingcc
* @DateTime 2017-03-23T13:29:22+0800
* @param {Function} cb callback
* @return {[type]} callback results
*/
function readMutiLines(cb) {
let datas = [];
process.stdin.setEncoding('utf8');
process.stdin.pause();
process.stdin.on('readable', function(chunk) {
if (chunk = process.stdin.read())
datas.push(chunk.slice(0, -1));
});
process.stdin.on('end', function() {
return cb(datas);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment