Introduction
Enquirer is a Node.js library for building interactive command-line prompts. It ships with a collection of built-in prompt types and a plugin system for creating custom ones. The library emphasizes speed, small footprint, and an intuitive API for CLI tool authors.
What Enquirer Does
- Provides 15+ built-in prompt types including input, confirm, select, multiselect, and autocomplete
- Supports prompt composition — chain multiple prompts or nest them inside each other
- Renders prompts with ANSI styling, spinners, and real-time validation feedback
- Offers a plugin architecture for registering custom prompt types
- Handles keypresses, cursor movement, and terminal resize events gracefully
Architecture Overview
Enquirer uses a base Prompt class that manages the prompt lifecycle: initialize, render, keypress handling, submit, and cancel. Each built-in prompt type extends this class with specific rendering and validation logic. The rendering engine writes directly to the terminal using ANSI escape codes, avoiding heavy dependencies on large TUI frameworks. State changes trigger re-renders, keeping the display in sync with user input.
Self-Hosting & Configuration
- Install via npm; no native dependencies or build steps required
- Import individual prompt types for smaller bundles:
const { Select } = require('enquirer') - Customize appearance with theme options for colors, symbols, and separator styles
- Set default values, initial input, and validation functions per prompt
- Works in any Node.js environment with TTY support
Key Features
- 15+ prompt types out of the box (input, number, confirm, select, multiselect, scale, sort, snippet, etc.)
- Real-time input validation with customizable error messages
- Autocomplete and fuzzy-matching for large option lists
- Composable prompt chains with conditional branching
- Small footprint with no heavy dependencies
Comparison with Similar Tools
- Inquirer.js — the most popular prompt library; larger dependency tree and slower rendering than Enquirer
- prompts — minimal and lightweight; fewer built-in prompt types and less customization
- @clack/prompts — modern prompt library with beautiful defaults; newer with a smaller ecosystem
- readline (Node.js built-in) — low-level; requires manual input handling and rendering
FAQ
Q: How does Enquirer compare to Inquirer.js? A: Enquirer is faster, has fewer dependencies, and offers a more extensible plugin system. Inquirer has broader ecosystem adoption and more third-party plugins.
Q: Can I create custom prompt types?
A: Yes. Extend the base Prompt class and register your custom type with enquirer.register('myType', MyPrompt).
Q: Does Enquirer support async validation? A: Yes. Pass an async function as the validate option; the prompt waits for resolution before accepting or rejecting input.
Q: Can I use Enquirer in CI/non-interactive environments? A: Enquirer requires a TTY. In CI, provide answers programmatically via the initial/default options or skip prompts.