Consider the following example
process.stdin.resume();
process.stdin.on("data", function(data) {
console.log("recieved " + data)
})
process.stdin.write("foo\n")
process.stdin.write("bar\n")
When I type something in terminal, I get
received something
Why it doesn't work in the same way for foo and bar which I sent earlier using stdin.write?
E.g. how can I trigger this event (stdin.on("data)) in the code? I was expected process.stdin.write to do this, but I'm just getting the same output back.
It's a Readable Stream that gets its input from the stdin file descriptor. I don't think you can write into that descriptor (but you could connect it to another writable descriptor).
However, the easiest solution in your case it to just simulate the 'data' events. Every stream is an EventEmiiter, so the following will work:
process.stdin.resume();
process.stdin.on("data", function(data)
console.log("recieved " + data)
});
process.stdin.emit('data', 'abc');