Prompts
Lightweight, dependency-free CLI prompt library supporting text, select, multiselect, and confirm question types.
Official Documentation ↗v2. Check the official docs for the latest API surface.Installation
npm install promptspnpm add promptsMethods
No methods match this filter.
Overview
Prompts is a lightweight CLI prompt library supporting text, select, multiselect, and confirm questions without heavy dependencies. This reference lists the most frequently used APIs with accurate signatures and runnable snippets.
Core APIs
prompts— Runs one or more questions and resolves with the answers keyed by each question name.select question— Renders a single-choice list and returns the selected value or its name.onCancel— Hooks into cancellation so scripts can abort gracefully when the user presses Ctrl+C.
Example
const prompts = require('prompts');
const res = await prompts({
type: 'text',
name: 'project',
message: 'Project name?',
});
console.log(res.project);
Notes
Cancelled prompts yield undefined answers, so always check before using them. Provide onCancel for a graceful exit.
Verification
Run a text prompt with an answer and confirm the resolved object contains that value under the question name.
Errors
The following points are quoted verbatim from the official documentation. 来源:https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:53.629Z. 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 value is an instance of Error it will simulate the user cancelling/exiting the prompt. (https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md)
- Should return true if the value is valid, and an error message String otherwise. (https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md)
- If false is returned, a default error message is shown | | max | number | Max value. (https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md)
Security notes
Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:51:53.629Z.
- This prompt is a similar to a prompt of type ‘text’ with style set to ‘password’. (https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md)
- Defaults to 1 | | style | string | Render style (default, password, invisible, emoji). (https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md)
- Defaults to 10 | | style | string | Render style (default, password, invisible, emoji). (https://cdn.jsdelivr.net/gh/terkelg/prompts@latest/readme.md)
FAQ
- How do I cancel prompts programmatically?
- Pass an AbortSignal to the prompt via its options, or rely on the onCancel handler when the user interrupts.
- Can I validate answers before accepting?
- Set a validate function on a question; returning a string shows an error message and re-prompts.
- Why are answers undefined after cancelling?
- Cancelling leaves answer keys undefined; check for that and abort the flow instead of proceeding.
Report a problem with this API docOpens a pre-filled issue on GitHub.