I am not understanding why I cannot call the end
event in this code below. I have already read too many things about how to do it, and I understand that I need to switch the stream (process.stdin) into a flowing mode. But if I have a data
event in my code, isn't it automaticaly in flowing mode? I have already tried process.stdin.resume()
and .pipe()
. I am runing this on Node.js.
Thanks very much.
// begin snippet: js hide: false console: true babel: false
// language: lang-js
var i=0;
process.stdin.resume();
process.stdin.setEncoding("utf-8");
var stdin_input = "";
process.stdin.on("data", function (input) {
stdin_input += input;
i++
if(i>5){
//do something to call "end" event at the bottom
i=0
}
});
process.stdin.on("end", function () {
console.log(stdin_input);
});
// end snippet