We can echo line by line on nodejs via stream pipe from stdin to stdout, i.e. from Readable to Writable stream:
process.stdin.pipe(process.stdout);
Confusingly, it also works same as before from stdout to stdin, i.e. from Writable to Readable stream below. Why?
process.stdout.pipe(process.stdin);
@EDIT
The similar test with io.Copy in golang has reproduced the aforementioned issue. The cross-validation seems to hint the builtin pipe implementation can't be wrong on both incumbent platforms.
package main
import (
"io"
"os"
)
func main() {
io.Copy(os.Stdout, os.Stdin)
// io.Copy(os.Stdin, os.Stdout) /* Also works than expected. */
}
@EDIT 2
For further investigation another test with Deno.copy on the third platform deno behaves as expected:
Deno.copy(Deno.stdout, Deno.stdin); /* Works as expected. */
// Deno.copy(Deno.stdin, Deno.stdout); /* Fails as expected. */