简体   繁体   中英

Node.js prompt module not honoring options

I've got a relatively simple chunk of node.js code that is my first attempt at using the prompt module. Have a look:

const schema = {
  properties : {
    username : {
      description : "Please enter username", type : "string", required : true,
      validator: /^[a-zA-Z0-9]+$/, warning : "must be comprised of letters and numbers only"
    }
  }
};
prompt.start();
prompt.get(schema, function (inError, inResult) {
  if (!inError) {
    userInfo.username = inResult.username;
  }
});

See, not too tough. The problem is that when I run it, the output is this:

"username: "

...whereas it should be this...

"Please enter username: "

It's not honoring the description option and I'm banging my head on the desk trying to figure out why. It's probably some stupid programmer trick on my part, but I'm just not seeing it. I've tried just passing properties by itself, not as part of an outer schema object, but that makes no difference. What's worse is it DOES seem to be honoring the validator, so it seems like perhaps a bug?

Anyone have any ideas? Thanks!

You should replace description with message . This isn't a change that is documented.

username : {
      message : "Please enter username", type : "string", required : true,
      validator: /^[a-zA-Z0-9]+$/, warning : "must be comprised of letters and numbers only"
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM