Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

enquirer

> 开发工具
Open source

Stylish, intuitive and user-friendly prompts. Used by eslint, webpack, yarn, pm2, pnpm, RedwoodJS, FactorJS, salesforce, Cypress, Google Lighthouse, Generate, t

8.0K stars0 likes3 views
WebsiteGitHub

About

Stylish, intuitive and user-friendly prompts. Used by eslint, webpack, yarn, pm2, pnpm, RedwoodJS, FactorJS, salesforce, Cypress, Google Lighthouse, Generate, t

Enquirer



Stylish CLI prompts that are user-friendly, intuitive and easy to create.
>_ Prompts should be more like conversations than inquisitions▌


(Example shows Enquirer's Survey Prompt)
The terminal in all examples is Hyper, theme is hyper-monokai-extended.

See more prompt examples



Created by jonschlinkert and doowb, Enquirer is fast, easy to use, and lightweight enough for small projects, while also being powerful and customizable enough for the most advanced use cases.

  • Fast - Loads in ~4ms (that's about 3-4 times faster than a single frame of a HD movie at 60fps)
  • Lightweight - Only one dependency, the excellent ansi-colors by Brian Woodward.
  • Easy to implement - Uses promises and async/await and sensible defaults to make prompts easy to create and implement.
  • Easy to use - Thrill your users with a better experience! Navigating around input and choices is a breeze. You can even create quizzes, or record and playback key bindings to aid with tutorials and videos.
  • Intuitive - Keypress combos are available to simplify usage.
  • Flexible - All prompts can be used standalone or chained together.
  • Stylish - Easily override semantic styles and symbols for any part of the prompt.
  • Extensible - Easily create and use custom prompts by extending Enquirer's built-in prompts.
  • Pluggable - Add advanced features to Enquirer using plugins.
  • Validation - Optionally validate user input with any prompt.
  • Well tested - All prompts are well-tested, and tests are easy to create without having to use brittle, hacky solutions to spy on prompts or "inject" values.
  • Examples - There are numerous examples available to help you get started.

If you like Enquirer, please consider starring or tweeting about this project to show your support. Thanks!


>_ Ready to start making prompts your users will love? ▌



❯ Getting started

Get started with Enquirer, the most powerful and easy-to-use Node.js library for creating interactive CLI prompts.

  • Install
  • Usage
  • Enquirer
  • Prompts
    • Built-in Prompts
    • Custom Prompts
  • Key Bindings
  • Options
  • Release History
  • Performance
  • About

❯ Install

Install with npm:

bash
npm install enquirer --save

Install with yarn:

bash
yarn add enquirer

(Requires Node.js 8.6 or higher. Please let us know if you need support for an earlier version by creating an issue.)


❯ Usage

Single prompt

The easiest way to get started with enquirer is to pass a question object to the prompt method.

javascript
const { prompt } = require('enquirer');

const response = await prompt({
  type: 'input',
  name: 'username',
  message: 'What is your username?'
});

console.log(response); // { username: 'jonschlinkert' }

(Examples with await need to be run inside an async function)

Multiple prompts

Pass an array of "question" objects to run a series of prompts.

javascript
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' }

Different ways to run enquirer

1. By importing the specific built-in prompt

javascript
const { Confirm } = require('enquirer');

const prompt = new Confirm({
  name: 'question',
  message: 'Did you like enquirer?'
});

prompt.run()
  .then(answer => console.log('Answer:', answer));

2. By passing the options to prompt

javascript
const { prompt } = require('enquirer');

prompt({
  type: 'confirm',
  name: 'question',
  message: 'Did you like enquirer?'
})
  .then(answer => console.log('Answer:', answer));

Jump to: Getting Started · Prompts · Options · Key Bindings


❯ Enquirer

Enquirer is a prompt runner

Add Enquirer to your JavaScript project with following line of code.

javascript
const Enquirer = require('enquirer');

The main export of this library is the Enquirer class, which has methods and features designed to simplify running prompts.

javascript
const { prompt } = require('enquirer');
const questions = [
  {
    type: 'input',
    name: 'username',
    message: 'What is your username?'
  },
  {
    type: 'password',
    name: 'password',
    message: 'What is your password?'
  }
];

const answers = await prompt(questions);
console.log(answers);

Prompts control how values are rendered and returned

Each individual prompt is a class with special features and functionality for rendering the types of values you want to show users in the terminal, and subsequently returning the types of values you need to use in your application.

How can I customize prompts?

Below in this guide you will find information about creating custom prompts. For now, we'll focus on how to customize an existing prompt.

All of the individual prompt classes in this library are exposed as static properties on Enquirer. This allows them to be used directly without using enquirer.prompt().

Use this approach if you need to modify a prompt instance, or listen for events on the prompt.

Example

javascript
const { Input } = require('enquirer');
const prompt = new Input({
  name: 'username',
  message: 'What is your username?'
});

prompt.run()
  .then(answer => console.log('Username:', answer))
  .catch(console.error);

Enquirer

Create an instance of Enquirer.

Params

  • options {Object}: (optional) Options to use with all prompts.
  • answers {Object}: (optional) Answers object to initialize with.

Example

javascript
const Enquirer = require('enquirer');
const enquirer = new Enquirer();

register()

Register a custom prompt type.

Params

  • type {String}
  • fn {Function|Prompt}: Prompt class, or a function that returns a Prompt class.
  • returns {Object}: Returns the Enquirer instance

Example

javascript
const Enquirer = require('enquirer');
const enquirer = new Enquirer();
enquirer.register('customType', require('./custom-prompt'));

prompt()

Prompt function that takes a "question" object or array of question objects, and returns an object with responses from the user.

Params

  • questions {Array|Object}: Options objects for one or more prompts to run.
  • returns {Promise}: Promise that returns an "answers" object with the user's responses.

Example

javascript
const Enquirer = require('enquirer');
const enquirer = new Enquirer();

const response = await enquirer.prompt({
  type: 'input',
  name: 'username',
  message: 'What is your username?'
});
console.log(response);

use()

Use an enquirer plugin.

Params

  • plugin {Function}: Plugin function that takes an instance of Enquirer.
  • returns {Object}: Returns the Enquirer instance.

Example

javascript
const Enquirer = require('enquirer');
const enquirer = new Enquirer();
const plugin = enquirer => {
  // do stuff to enquire instance
};
enquirer.use(plugin);

Enquirer#prompt

Prompt function that takes a "question" object or array of question objects, and returns an object with responses from the user.

Params

  • questions {Array|Object}: Options objects for one or more prompts to run.
  • returns {Promise}: Promise that returns an "answers" object with the user's responses.

Example

javascript
const { prompt } = require('enquirer');
const response = await prompt({
  type: 'input',
  name: 'username',
  message: 'What is your username?'
});
console.log(response);

❯ Prompts

This section is about Enquirer's prompts: what they look like, how they work, how to run them, available options, and how to customize the prompts or create your own prompt concept.

Getting started with Enquirer's prompts

  • Prompt - The base Prompt class used by other prompts
    • Prompt Options
  • Built-in prompts
  • Prompt Types - The base Prompt class used by other prompts
  • Custom prompts - Enquirer 2.0 introduced the concept of prompt "types", with the goal of making custom prompts easier than ever to create and use.

Prompt

The base Prompt class is used to create all other prompts.

javascript
const { Prompt } = require('enquirer');
class MyCustomPrompt extends Prompt {}

See the documentation for creating custom prompts to learn more about how this works.

Prompt Options

Each prompt takes an options object (aka "question" object), that implements the following interface:

javascript
{
  // required
  type: string | function,
  name: string | function,
  message: string | function | async function,

  // optional
  skip: boolean | function | async function,
  initial: string | function | async function,
  format: function | async function,
  result: function | async function,
  validate: function | async function,
}

Each property of the options object is described below:

Property Required? Type Description
type yes string|function Enquirer uses this value to determine the type of prompt to run, but it's optional when prompts are run directly.
name yes string|function Used as the key for the answer on the returned values (answers) object.
message yes string|function The message to display when the prompt is rendered in the terminal.
skip no boolean|function If true it will not ask that prompt.
initial no string|function The default value to return if the user does not supply a value.
format no function Function to format user input in the terminal.
result no function Function to format the final submitted value before it's returned.
validate no function Function to validate the submitted value before it's returned. This function may return a boolean or a string. If a string is returned it will be used as the validation error message.

Example usage

javascript
const { prompt } = require('enquirer');

const question = {
  type: 'input',
  name: 'username',
  message: 'What is your username?'
};

prompt(question)
  .then(answer => console.log('Answer:', answer))
  .catch(console.error);

Built-in prompts

  • AutoComplete Prompt
  • BasicAuth Prompt
  • [Confirm Prompt](#confir

Issues· 207 open

View all issuesOpen on GitHub
  • #483

    [bug] Strg+C results in uncaught exception

    Updated May 22, 2026
  • #477

    Feature Request: Is there a possibility to have a progress bar interface while a job is running in background?

    Updated Oct 5, 2025
  • #342

    Input history prevents leaving field empty

    Updated Sep 19, 2025
  • #480

    When no TTY if the event loop becomes empty node exits with code 0

    Updated Sep 11, 2025
  • #463

    TypeScript: Infer `prompt()` return type object shape from question objects

    Updated Aug 7, 2025
  • #479

    initial value (masked) not showing in passwordPrompt until after first keypress

    Updated Jul 28, 2025
  • #201

    Multiselect prompt does not work with initial function

    bugUpdated May 6, 2025
  • #362

    Export individual PromptOptions

    Updated Dec 24, 2024
  • #474

    is there a way to use ctrl-p and ctrl-n to navigate through autocomplete list?

    Updated Oct 24, 2024
  • #339

    Skipping multiple select throws an exception

    Updated Oct 12, 2024

> Tags

JavaScriptbashclicommand-lineconfirm

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedOct 1, 2026
Category开发工具
PricingOpen source

> Related tools

V
VS Code
流行的开源代码编辑器
G
Git
分布式版本控制系统
V
Vite
下一代前端构建工具