Skip to content

Instantly share code, notes, and snippets.

@kingcc

kingcc/readMutiLines

Last active Mar 23, 2017
Embed
What would you like to do?
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