Enquirer
Stylish, extensible CLI prompt system with many prompt types, validation, and customizable rendering.
Official Documentation ↗v2. Check the official docs for the latest API surface.Installation
npm install enquirerpnpm add enquirerMethods
No methods match this filter.
Overview
Enquirer is a stylish and extensible CLI prompt system with many prompt types, validation, and customizable rendering. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
prompt— Runs a list of questions and resolves with the collected answers.new Input— Constructs a single text prompt instance you can run or nest.new Select— Creates a single-choice prompt with arrow-key navigation.
Example
const { prompt } = require('enquirer');
const answers = await prompt([
{ type: 'input', name: 'name', message: 'Your name?' },
]);
console.log(answers.name);
Notes
Prompts are classes, so they can be instantiated, reused, and composed for wizards. Validation runs per prompt and re-asks on failure.
Verification
Run an Input prompt with a validate function and confirm an invalid entry causes a re-prompt until valid.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/enquirer/enquirer@latest/README.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:49:23.351Z. Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- If a string is returned it will be used as the validation error message. (https://cdn.jsdelivr.net/gh/enquirer/enquirer@latest/README.md)
FAQ
- How do I add validation to a prompt?
- Provide a validate function returning true or an error message; Enquirer re-prompts until it passes.
- Can I build a multi-step wizard?
- Use the Snippet or Form prompt to collect several fields on one screen, or chain prompt calls sequentially.
- How do I reuse previous answers?
- Pass an answers object as the second argument so later prompts can reference earlier values in their messages.
Report a problem with this API docOpens a pre-filled issue on GitHub.