Lightweight, beautiful and user-friendly prompts
prompts is a lightweight, promise-based library for building interactive command-line interfaces in Node.js applications. With over 36 million weekly downloads, it has become a popular choice for developers who need to collect user input in CLI tools, build scripts, and automation workflows. The package provides a clean API that works seamlessly with async/await, making it straightforward to chain multiple questions and handle user responses programmatically.
The library was created to address the complexity and heavy dependency footprint of earlier prompt libraries. By focusing on a minimal core with zero external dependencies, prompts delivers essential functionality without bloating project bundles. It supports multiple prompt types including text input, confirmations, selections, toggles, and more complex inputs like multi-select and autocomplete, all with a consistent API structure.
Developers choose prompts when building CLI applications that require user interaction—from simple configuration wizards to complex deployment scripts. The package shines in modern JavaScript environments where promises and async/await are standard, and it includes built-in testing utilities that make it practical to write automated tests for interactive CLI tools. Its small size and focused feature set make it particularly suitable for libraries and tools that will be distributed via npm.
import prompts from 'prompts';
async function setupProject() {
const questions = [
{
type: 'text',
name: 'projectName',
message: 'Project name:',
validate: value => value.length < 3 ? 'Name must be at least 3 characters' : true
},
{
type: 'select',
name: 'framework',
message: 'Choose a framework:',
choices: [
{ title: 'React', value: 'react' },
{ title: 'Vue', value: 'vue' },
{ title: 'Svelte', value: 'svelte' }
]
},
{
type: prev => prev === 'react' ? 'toggle' : null,
name: 'typescript',
message: 'Use TypeScript?',
initial: true,
active: 'yes',
inactive: 'no'
},
{
type: 'multiselect',
name: 'features',
message: 'Select features:',
choices: [
{ title: 'ESLint', value: 'eslint', selected: true },
{ title: 'Prettier', value: 'prettier', selected: true },
{ title: 'Testing', value: 'testing' }
]
}
];
const response = await prompts(questions, {
onCancel: () => {
console.log('Setup cancelled');
process.exit(0);
}
});
console.log('\nConfiguration:', response);
return response;
}
setupProject();CLI Configuration Tools: Build interactive setup wizards that guide users through application configuration, collecting database credentials, API keys, and preferences with validation before writing config files.
Project Scaffolding: Create project generators similar to create-react-app or Vue CLI that ask users about framework preferences, features to include, and project structure before generating boilerplate code.
Deployment Scripts: Implement interactive deployment workflows that confirm environment selection, prompt for version numbers, and request confirmation before executing destructive operations like database migrations.
Data Collection Scripts: Build maintenance scripts that require operator input during execution, such as batch processing tools that occasionally need manual decisions about edge cases or data conflicts.
Testing and CI/CD Tools: Develop build tools that conditionally prompt for parameters when running locally but use environment variables in automated environments, using the inject() method for non-interactive test execution.
npm install promptspnpm add promptsbun add prompts