Security News
Cloudflare Adds Security.txt Setup Wizard
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
The inquirer npm package is a collection of common interactive command line user interfaces. It provides an easy way to capture user input in a variety of ways such as lists, confirmations, and text input, which are useful for building command-line tools and scripts.
Text Input
Captures freeform text input from the user.
const inquirer = require('inquirer');
inquirer.prompt([{ type: 'input', name: 'username', message: 'What is your username?' }]).then(answers => { console.log(`Hello, ${answers.username}!`); });
Confirmation
Asks the user a yes/no question.
const inquirer = require('inquirer');
inquirer.prompt([{ type: 'confirm', name: 'continue', message: 'Do you wish to continue?' }]).then(answers => { console.log(`You chose to ${answers.continue ? 'continue' : 'stop'}.`); });
List
Presents a list of options for the user to choose from.
const inquirer = require('inquirer');
inquirer.prompt([{ type: 'list', name: 'selection', message: 'Choose an option:', choices: ['Option 1', 'Option 2', 'Option 3'] }]).then(answers => { console.log(`You selected: ${answers.selection}`); });
Checkbox
Allows the user to select multiple options from a list.
const inquirer = require('inquirer');
inquirer.prompt([{ type: 'checkbox', name: 'features', message: 'What features do you want?', choices: ['Feature A', 'Feature B', 'Feature C'] }]).then(answers => { console.log(`You selected: ${answers.features.join(', ')}`); });
Password
Asks the user for a password, input is hidden on the terminal.
const inquirer = require('inquirer');
inquirer.prompt([{ type: 'password', name: 'password', message: 'Enter your password:' }]).then(answers => { console.log('Password captured'); });
Prompt is another command-line input collector with a slightly different API. It has a simpler interface but lacks some of the more advanced features and UI components that inquirer provides.
Enquirer is a stylish, minimal alternative to inquirer with a more modern promise-based API. It offers similar functionality but with a focus on being lightweight and fast.
Vorpal is a framework for building interactive CLI applications. It includes a command-line interface with a suite of interactive prompts, but it's more focused on building the entire CLI tool rather than just handling prompts.
A collection of common interactive command line user interfaces.
We strive at providing easily embeddable and beautiful command line interface for Node.js ; some hope in becoming the CLI Xanadu.
Inquirer should ease the process of asking end user questions, parsing, validating answers, managing hierarchical prompts and providing error feedback.
Inquirer provide the user interface, and the inquiry session flow. If you're searching for a full blown command line program utility, then check out Commander.js (inspired by) or Cli-color (used internally).
npm install inquirer
var inquirer = require("inquirer");
inquirer.prompt([/* Pass your questions in here */], function( answers ) {
// Use user feedback for... whatever!!
});
Checkout the examples/
folder for code and interface examples.
node examples/pizza.js
# etc
inquirer.prompt( questions, callback )
Launch the prompt interface (inquiry session)
A question object is a hash
containing question related values:
input
- Possible values: input
, confirm
,
list
, rawlist
strings
, or objects
containing a name
(to display) and a value
properties (to save in the answers hash).true
if the value is valid, and an error message (String
) otherwise. If false
is returned, a default error message is provided.true
or false
depending on wheter or not this question should be asked.validate
, filter
and when
functions can be asynchronously using this.async()
. You just have to pass the value you'd normally return to the callback option.
{
validate: function(input) {
// Declare function as asynchronous, and save the done callback
var done = this.async();
// Do async stuff
setTimeout(function() {
if (typeof input !== "number") {
// Pass the return value in the done callback
done("You need to provide a number");
return;
}
// Pass the return value in the done callback
done(true);
}, 3000);
}
}
A key/value hash containing the client answers in each prompt.
name
property of the question objectconfirm
: (Boolean)input
: User input (filtered if filter
is defined) (String)rawlist
, list
: Selected choice value (or name if no value specified) (String)allowed options written inside square brackets ([]
) are optional. Others are required.
{ type: "list" }
Take type
, name
, message
, choices
[, default
, filter
] properties. (Note that
default must be the choice index
in the array)
{ type: "rawlist" }
Take type
, name
, message
, choices
[, default
, filter
] properties. (Note that
default must the choice index
in the array)
{ type: "expand" }
Take type
, name
, message
, choices
[, default
, filter
] properties. (Note that
default must be the choice index
in the array)
Note that the choice
object will take an extra parameter called key
for the expand
prompt. This parameter must be a single (lowercased) character. The h
option is added by the prompt and shouldn't be defined by the user.
See examples/expand.js
for a running example.
{ type: "checkbox" }
Take type
, name
, message
, choices
[, filter
, validate
] properties.
Choices marked as { checked: true }
will be checked by default.
{ type: "confirm" }
Take type
, name
, message
[, default
] properties. default
is expected to be a boolean if used.
{ type: "input" }
Take type
, name
, message
[, default
, filter
, validate
] properties.
{ type: "password" }
Take type
, name
, message
[, default
, filter
, validate
] properties.
You should expect mostly good support for the CLI below. This does not mean we won't look at issues found on other command line - feel free to report any!
Please refer to the Github releases section for the changelog
Style Guide: Please base yourself on Idiomatic.js style guide with two space indent
Unit test: Unit test are wrote in Mocha. Please add a unit test for every new feature
or bug fix. npm test
to run the test suite.
Documentation: Add documentation for every API change. Feel free to send corrections
or better docs!
Pull Requests: Send fixes PR on the master
branch. Any new features should be send on the wip
branch.
We're looking to offer good support for multiple prompts and environments. If you want to help, we'd like to keep a list of testers for each terminal/OS so we can contact you and get feedback before release. Let us know if you want to be added to the list (just tweet to @vaxilart) or just add your name to the wiki
Copyright (c) 2012 Simon Boudrias (twitter: @vaxilart)
Licensed under the MIT license.
FAQs
A collection of common interactive command line user interfaces.
The npm package inquirer receives a total of 28,749,036 weekly downloads. As such, inquirer popularity was classified as popular.
We found that inquirer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Cloudflare has launched a setup wizard allowing users to easily create and manage a security.txt file for vulnerability disclosure on their websites.
Security News
The Socket Research team breaks down a malicious npm package targeting the legitimate DOMPurify library. It uses obfuscated code to hide that it is exfiltrating browser and crypto wallet data.
Security News
ENISA’s 2024 report highlights the EU’s top cybersecurity threats, including rising DDoS attacks, ransomware, supply chain vulnerabilities, and weaponized AI.