enquirer
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|---|---|---|---|---|
ansi-colors | 4.1.3 | 8.53 kB | MIT | prod | |
strip-ansi | 6.0.1 | 1.99 kB | MIT | prod |
Enquirer is a stylish, intuitive, and user-friendly prompt system for Node.js. It is designed to be fast and lightweight, making it suitable for small projects, while also being powerful and extensible, thus catering to the most advanced use cases. It offers a range of different prompts, including input prompts, list prompts, confirm prompts, and multiple select prompts among others, in a conversational style. Notably, enquirer places a strong emphasis on easy implementation, user experience, and customizability.
Using Enquirer is quite straightforward. After installing it through npm or yarn, you simply require the package in your project and use it to create prompts. Here are some examples:
const { prompt } = require('enquirer');
// Single prompt
const response = await prompt({
type: 'input',
name: 'username',
message: 'What is your username?'
});
console.log(response); // { username: 'jonschlinkert' }
// Multiple prompts
const response = await prompt([
{
type: 'input',
name: 'name',
message: 'What is your name?'
},
{
type: 'input',
name: 'username',
message: 'What is your username?'
}
]);
console.log(response); // { name: 'Edward Chan', username: 'edwardmchan' }
// Confirm prompt
const { Confirm } = require('enquirer');
const prompt = new Confirm({
name: 'question',
message: 'Did you like enquirer?'
});
prompt.run()
.then(answer => console.log('Answer:', answer));
The prompt()
function can be used with a single question object or an array of question objects. This function returns a Promise that resolves to an answers object.
The documentation for Enquirer can be found in the project's GitHub repository. There you will find an extensive README file that includes a getting started guide, clear usage examples, and detailed descriptions of the various prompt options and features available. In particular, you can learn more about built-in prompts, custom prompts, key bindings, options, and more. Also, it is worth noting that the examples directory in the repository provides a number of example scripts that demonstrate various use-cases for Enquirer prompts.