A collection of common interactive command line user interfaces.
Give it a try in your own terminal!
npx @inquirer/demo@latest
npm install @inquirer/prompts
yarn add @inquirer/prompts
Inquirer recently underwent a rewrite from the ground up to reduce the package size and improve performance. The previous version of the package is still maintained (though not actively developed), and offered hundreds of community contributed prompts that might not have been migrated to the latest API. If this is what you're looking for, the previous package is over here.
import { input } from '@inquirer/prompts';
const answer = await input({ message: 'Enter your name' });
import { input } from '@inquirer/prompts';
See documentation for usage example and options documentation.
import { select } from '@inquirer/prompts';
See documentation for usage example and options documentation.
import { checkbox } from '@inquirer/prompts';
See documentation for usage example and options documentation.
import { confirm } from '@inquirer/prompts';
See documentation for usage example and options documentation.
import { password } from '@inquirer/prompts';
See documentation for usage example and options documentation.
import { expand } from '@inquirer/prompts';
See documentation for usage example and options documentation.
Launches an instance of the users preferred editor on a temporary file. Once the user exits their editor, the content of the temporary file is read as the answer. The editor used is determined by reading the $VISUAL or $EDITOR environment variables. If neither of those are present, the OS default is used (notepad on Windows, vim on Mac or Linux.)
import { editor } from '@inquirer/prompts';
See documentation for usage example and options documentation.
import { rawlist } from '@inquirer/prompts';
See documentation for usage example and options documentation.
The API documentation is over here, and our testing utilities here.
All inquirer prompts are a function taking 2 arguments. The first argument is the prompt configuration (unique to each prompt). The second is providing contextual or runtime configuration.
The context options are:
Property | Type | Required | Description |
---|---|---|---|
input | NodeJS.ReadableStream |
no | The stdin stream (defaults to process.stdin ) |
output | NodeJS.WritableStream |
no | The stdout stream (defaults to process.stdout ) |
clearPromptOnDone | boolean |
no | If true, we'll clear the screen after the prompt is answered |
Example:
import { confirm } from '@inquirer/prompts';
const allowEmail = await confirm(
{ message: 'Do you allow us to send you email?' },
{
output: new Stream.Writable({
write(chunk, _encoding, next) {
// Do something
next();
},
}),
clearPromptOnDone: true,
},
);
All prompt functions are returning a cancelable promise. This special promise type has a cancel
method that'll cancel and cleanup the prompt.
On calling cancel
, the answer promise will become rejected.
import { confirm } from '@inquirer/prompts';
const answer = confirm(...); // note: for this you cannot use `await`
answer.cancel();
When asking many questions, you might not want to keep one variable per answer everywhere. In which case, you can put the answer inside an object.
import { input, confirm } from '@inquirer/prompts';
const answers = {
firstName: await input({ message: "What's your first name?" }),
allowEmail: await confirm({ message: 'Do you allow us to send you email?' }),
};
console.log(answers.firstName);
Maybe some questions depend on some other question's answer.
import { input, confirm } from '@inquirer/prompts';
const allowEmail = await confirm({ message: 'Do you allow us to send you email?' });
let email;
if (allowEmail) {
email = await input({ message: 'What is your email address' });
}
import { setTimeout } from 'node:timers/promises';
import { input } from '@inquirer/prompts';
const ac = new AbortController();
const prompt = input({
message: 'Enter a value (timing out in 5 seconds)',
});
prompt
.finally(() => {
ac.abort