README.md

promptly

Installation

$ npm install promptly

API

.prompt(message, [opts], fn)

Prompts for a value, printing the message and waiting for the input.
When done, calls fn with error and value.

Default options:

{
// The default value. If not supplied, the input is mandatory'default':null,
// Automatically trim the input'trim':true,
// A validator or an array of validators.'validator':null,
// Automatically retry if a validator fails'retry':true,
// Do not print what the user types'silent':false,
// Input and output streams to read and write to'input':process.stdin,
'output':process.stdout
}

promptly.prompt('Name: ', function (err, value) {
// err is always null in this case, because no validators are setconsole.log(value);
});

Ask for a name with a constraint (non-empty value and length > 2):

varvalidator=function (value) {
if (value.length<2) {
thrownewError('Min length of 2');
}
return value;
};
promptly.prompt('Name: ', { validator: validator }, function (err, value) {
// Since retry is true by default, err is always null// because promptly will be prompting for a name until it validates// Between each prompt, the error message from the validator will be printedconsole.log('Name is:', value);
});