My assumption is that the data event should only really be used in conjunction with stdin… (in the context of using stdin and stdout)
I do not understand why it can be used with stdout… (basically – why is it even permitted?)… When it is used – it seems to somehow overwrite any previous stdin.on(“data”…) listener – and has even more odd behaviour when used before a stdin.on(“data”…) listener
Example 1:
` process.stdin.on(“data”, (data) => {
process.stdout.write(data.toString());
});
process.stdout.on("data", (data) => {
process.stdout.write(data.toString().toUpperCase());
});`
When run from the terminal and inputting (one after the other) test0, test1, test2 and test 3 yields…:
test0
TEST0
test1
TEST1
test2
TEST2
test3
TEST3
It would therefore appear that the stdin listener is not operational(?)…
Example 2:
` process.stdout.on(“data”, (chunk) => {
process.stdout.write(chunk.toString().toUpperCase());
});
process.stdin.on("data", (chunk) => {
process.stdout.write(chunk.toString());
});`
When run from the terminal and inputting (one after the other) test0, test1, test2 and test 3 yields…:
test0
test0
test1
TEST1
test2
test2
test3
TEST3
This the second example seems to flip between the two listeners…
Apologies if this is a really stupid question, I have looked high and low for the answer but have been unable to find an answer….
I have described what I have tried above.
GreenBeef is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.