CrazySynthax
CrazySynthax

Reputation: 15008

node.js prompt: how to disable the appearance of the property name?

I wrote the following code using 'prompt' package. I defined:

message: ''

in order to disable the appearance of the property name 'username' in console whenever the program waits for the user to give an input.

var prompt = require('prompt');
prompt.message = '';
var schema = {
   properties: {
      username: {
         message: ''
      }
   }
};
console.log('Please type your username');
prompt.get(schema, function(err, result) {
   console.log('Command-line input received:');
   console.log('username is ' + result.username);
})

Still, it doesn't work out and the console prints:

Please type your username

username: myname Command-line input

received: username is myname

Upvotes: 2

Views: 1267

Answers (1)

apsillers
apsillers

Reputation: 115950

You probably want to use description: '' instead of message: ''.

There appears to be erroneous documentation about this:

The basic structure of a prompt is this:

prompt.message + prompt.delimiter + property.message + prompt.delimiter;

But this is not correct; property.message is used to explain a validation error, not appear in a prompt. Earlier in the documentation, it says (correctly) of description and message:

{
  description: 'Enter your password',  // Prompt displayed to the user. If not supplied name will be used.
  ...
  message: 'Password must be letters', // Warning message to display if validation fails.
  ...
}

Upvotes: 1

Related Questions