A collection of common interactive command line user interfaces.
Inquirer is a Node.js library for creating interactive command-line interfaces through customizable prompts. It returns promises with structured user input, supporting common prompt types like text input, confirmation dialogs, single/multiple choice lists, and password fields. With over 40 million weekly downloads, it's the de facto standard for CLI tools built with Node.js, powering scaffolding tools, build scripts, and developer utilities across the ecosystem.
The library solves the problem of collecting structured user input in terminal applications. Rather than parsing raw stdin or implementing custom readline logic, developers define questions as objects with validation rules, conditional logic, and type constraints. Inquirer handles the terminal interaction, cursor management, and input validation, returning clean key-value pairs ready for application logic.
Inquirer uses RxJS under the hood to enable reactive question flows where prompts can be dynamically injected based on previous answers. It supports both simple linear question sequences and complex branching logic through the 'when' property. The validation system allows synchronous and asynchronous checks with custom error messages, while filter and transformer functions provide input normalization and display formatting.
Note that as of 2023, the original inquirer package entered maintenance mode following a complete rewrite as @inquirer/prompts. The legacy package remains stable and widely used, but new projects should evaluate the modern TypeScript-based alternative for better performance and smaller bundle sizes. Existing inquirer codebases continue to work without migration pressure.
import inquirer from 'inquirer';
const answers = await inquirer.prompt([
{
type: 'input',
name: 'projectName',
message: 'Enter project name:',
default: 'my-app',
validate: (input) => {
if (!/^[a-z0-9-]+$/.test(input)) {
return 'Project name must contain only lowercase letters, numbers, and hyphens';
}
return true;
}
},
{
type: 'list',
name: 'framework',
message: 'Select a framework:',
choices: ['React', 'Vue', 'Svelte', 'Vanilla'],
default: 'React'
},
{
type: 'checkbox',
name: 'features',
message: 'Select features:',
choices: [
{ name: 'TypeScript', checked: true },
{ name: 'ESLint', checked: true },
{ name: 'Testing (Vitest)' },
{ name: 'Docker' }
]
},
{
type: 'confirm',
name: 'initGit',
message: 'Initialize git repository?',
default: true,
when: (answers) => answers.features.length > 0
},
{
type: 'password',
name: 'apiKey',
message: 'Enter API key (optional):',
mask: '*',
when: (answers) => answers.framework === 'React'
}
]);
console.log('\nConfiguration:');
console.log(`Project: ${answers.projectName}`);
console.log(`Framework: ${answers.framework}`);
console.log(`Features: ${answers.features.join(', ')}`);
if (answers.initGit) console.log('Git: enabled');
if (answers.apiKey) console.log('API Key: configured');Project scaffolding tools: Generators like Yeoman use inquirer to collect project configuration (name, author, license, dependencies) before creating file structures. The checkbox prompt type enables multi-select feature toggles, while validation ensures valid package names and semantic versions.
CI/CD deployment scripts: Build pipelines use inquirer to confirm destructive operations (database migrations, production deploys) or select deployment targets from dynamic environment lists. The confirm prompt with default values prevents accidental production updates.
Database migration utilities: CLI tools prompt for connection strings, migration direction (up/down), and batch size with password masking for credentials. Async validation can test database connectivity before proceeding with schema changes.
Configuration wizards: Setup scripts for frameworks or services collect API keys, server ports, and feature flags through sequential prompts. Conditional questions (via 'when') show advanced options only when users enable expert mode.
Interactive test runners: Developer tools prompt for test file patterns, coverage thresholds, or browser targets. The rawlist prompt displays numbered options for quick keyboard selection without arrow key navigation.
npm install inquirerpnpm add inquirerbun add inquirer