CreateInterface prints double in terminal

when using the readline interface, everything starting with stdin is printed twice in stdout:

var rl = require('readline'); var i = rl.createInterface(process.stdin, process.stdout); 

when I run this code, everything that I type in the terminal is duplicated. Entering "hello world" gives:

 hheelloo wwoorrlldd 

I assume it makes sense that he does this, since the readline module is designed to feed input to output. But isn't this also intended to be a command line interface? I am confused by how they should use it. Help?

+6
source share
3 answers

Try using terminal: false :

 var readline = require("readline"); var rl = readline.createInterface({ input: process.stdin, output: process.stdout, terminal: false }); 
+14
source

I had this problem, and I fixed it, making sure that I only have one readline.interface instance at a time. I would recommend defining the interface in the function that it uses, so that after you leave this context, it is cleared. Alternatively, you can simply declare a global instance that you use throughout your application. The main problem is that when you have two instances (or more) of listening to the same input stream ( process.stdin ), they both will pick up any input and they will process it / send to the same output stream ( process.stdout ). That is why you see the double.

+1
source

You must use the option object format:

 var i = rl.createInterface({ input: process.stdin, output: process.stdout }); 
-1
source

Source: https://habr.com/ru/post/971990/


All Articles