A simple commandline prompt for Node.js
While working on a Node.js automation software I needed to generate some files and code after collecting some information from the user. Most of the modules that I found were a bit of an over-kill, all I wanted was a good old prompt (the browser type) so I decided to write this module.
npm install simple-prompt
Simple prompt accepts an array of question objects
var prompt = require('simple-prompt');
var questions = [
{
question: 'Name',
required: true // required
},
{
question: 'Surname' //optional
},
{
question: 'Age',
required: true, // required
validate: function (answer) {
return parseInt(answer, 10) >= 18; // only 18 or higher
},
filter: function (answer) {
return parseInt(answer, 10); // bring back my answer as a number
}
}
];
prompt(questions, function (answers) {
console.log(answers);
});
The question object
has 4 properties that you can specify:
npm test