weirdpanda
weirdpanda

Reputation: 2626

Prompt module in NodeJS repeating the input

I'm making an application using NodeJS and its a CLI application; to get the input from the user, I'm using the "prompt" module. I can use it, but while typing in the prompt's prompt, each character is getting repeated, however the output is fine! The code is below. Please Help.

prompt.start();

    prompt.get({
      properties: {
        name: {
          description: "What is your name?".magenta
        }
      }
    }, function (err, result) {
      console.log("You said your name is: ".cyan + result.name.cyan);
    });

IMAGE: added

Upvotes: 2

Views: 2902

Answers (2)

weirdpanda
weirdpanda

Reputation: 2626

Before using the "prompt" module, I used the ReadLine interface; sadly I had the same problem. However, the fix was simple:

Remove the rli.close(); and then run it.

Then re-add the rli.close(); and it works!

Thanks mscdex for the input, though :)

Upvotes: 5

mscdex
mscdex

Reputation: 106696

FWIW if you just need simple prompting, you can use the built-in readline module's question() method (which does not exhibit the double output issue). Example:

var readline = require('readline');

var rli = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

rli.question('What is your name? ', function(answer) {
  console.log('You said your name is: ' + answer);
  rli.close();
});

Upvotes: 2

Related Questions