inquirer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
ansi-escapes | 4.3.2 | 5.13 kB | MIT | prod | |
chalk | 4.1.2 | 11.31 kB | MIT | prod | |
cli-cursor | 3.1.0 | 2.08 kB | MIT | prod | |
cli-width | 3.0.0 | 3.93 kB | ISC | prod | |
external-editor | 3.1.0 | 6.49 kB | MIT | prod | |
figures | 3.2.0 | 4.19 kB | MIT | prod | |
lodash | 4.17.21 | 311.49 kB | MIT | prod | |
mute-stream | 0.0.8 | 2.6 kB | ISC | prod | |
ora | 5.4.1 | 6.74 kB | MIT | prod | |
run-async | 2.4.1 | 2.72 kB | MIT | prod | |
rxjs | 7.8.1 | 734.42 kB | Apache-2.0 | prod | |
string-width | 4.2.3 | 2.33 kB | MIT | prod | |
strip-ansi | 6.0.1 | 1.99 kB | MIT | prod | |
through | 2.3.8 | 4.36 kB | MIT | prod | |
wrap-ansi | 7.0.0 | 4.22 kB | MIT | prod |
Inquirer.js is a user-friendly JavaScript library designed to help developers create intuitive command line interfaces. The library simplifies the task of creating several different types of prompts, including input prompts, confirmation prompts, list prompts, checkbox prompts, password prompts, and more. It offers a high degree of customization to allow developers to create interfaces that best suit their application's needs. Inquirer.js can be used for validating user inputs, managing hierarchical prompts, and facilitating interactive sessions to keep users engaged and informed during the command execution process.
To utilize the Inquirer.js package, you first need to install it using npm with the command npm install --save inquirer
. After installation, you can use it by importing Inquirer in your JavaScript file and using the inquirer.prompt()
function to prompt users for input.
Here's a simple example:
import inquirer from 'inquirer';
const question = [{
type: 'input',
name: 'username',
message: 'What\'s your username?',
}];
inquirer
.prompt(question)
.then(answer => {
console.log(`Hello, ${answer.username}!`);
})
.catch(error => {
console.error(error);
});
In the example above, a user is asked to provide a username. After they enter their username, it is logged to the console with a friendly greeting.
Remember that Inquirer.js only supports ESM imports from version 9 and onwards. For older versions, you can use the CommonJS require
syntax:
const inquirer = require('inquirer');
Also, Inquirer.js supports a reactive interface that allows for dynamic questions, through the inquirer.prompt()
method that returns a promise with the answers given by the user.
The documentation for Inquirer.js can be found at the root of the GitHub repository (https://github.com/SBoudrias/Inquirer.js). It consists of a detailed readme file which contains information on installation, examples, environment support, different types of prompts, and more. Examples of using Inquirer.js can be found in the examples
directory of the GitHub repository.