when using the readline interface, everything from stdin gets printed twice to stdout:
var rl = require('readline');
var i = rl.createInterface(process.stdin, process.stdout);
when i run this code, everything i type in the terminal is duplicated. Typing 'hello world' yields:
hheelloo wwoorrlldd
I guess it makes sense that it does this, since the readline module is meant to pipe an input to an output. But isnt it also meant to be used to create command line interfaces? I'm confused as to how im supposed to use it. Help?
Try using terminal: false
:
var readline = require("readline");
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});
I had this issue as well and I fixed it by ensuring that I only ever had one instance of a readline.interface
at a time. I would recommend scoping the interface in the function that it is being used in so that once you leave that context it is cleaned up. Alternatively, you could simply declare a global instance that you use everywhere in your application. The underlying issue here is that when you have two instances (or more) listening to the same input stream (process.stdin
) they will both pick up any input and they will both process it/ send it to the same output stream (process.stdout
). This is why you are seeing double.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With