explaingit

terkelg/prompts

9,275JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A lightweight Node.js library for adding interactive questions to command-line tools, text, multiple choice, date pickers, autocomplete, with built-in support for injecting answers in automated tests.

Mindmap

mindmap
  root((repo))
    What It Does
      Interactive CLI prompts
      Collect user answers
      Return answer object
    Input Types
      Text and numbers
      Single or multi select
      Date picker
      Autocomplete
    Features
      Answer injection
      Dynamic prompt chains
      No big dependencies
    Use Cases
      Setup wizards
      Automated testing
      Branching questions
    Audience
      CLI tool developers
      Node.js developers
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Build a CLI setup wizard that asks users for project name, language, and options before generating files.

USE CASE 2

Test a CLI tool without keyboard interaction by injecting pre-supplied answers programmatically.

USE CASE 3

Create a branching questionnaire where follow-up questions only appear based on how the user answered a previous one.

USE CASE 4

Add input validation to any prompt so users must provide a valid answer before the script continues.

Tech stack

JavaScriptNode.js

Getting it running

Difficulty · easy Time to first run · 5min
License not mentioned in the explanation.

In plain English

Prompts is a Node.js library for building interactive command-line interfaces. When you run a command-line tool and it asks you to type something, choose from a list, or confirm a choice before continuing, that interaction is usually powered by a library like this one. Prompts handles the input and display so developers do not have to write that logic from scratch. The library supports a range of input types: plain text, numbers, passwords, yes or no confirmations, single selections from a list, multiple selections from a list, date pickers, and autocomplete fields. Each prompt type is self-contained, so you can use just the ones you need. Prompts are defined as plain JavaScript objects with properties like the question text, the type of input expected, and optional validation logic. You pass one prompt or a list of prompts to the main function and it returns an object containing all the user's answers. One notable feature is programmatic injection, where you can pre-supply answers in code. This is intended for automated testing: instead of having a test script interact with the terminal manually, you inject the expected answers ahead of time and the prompts resolve without waiting for keyboard input. The library also supports dynamic prompt chains, where whether a particular question appears at all can depend on how the user answered a previous one. This is useful for wizards or setup flows where some follow-up questions are only relevant in certain situations. Prompts has no large dependencies and works with modern JavaScript async syntax. It supports Node 14 and above and is installed via npm. It is designed for developers building command-line tools who want to add interactive input collection without taking on a heavyweight dependency.

Copy-paste prompts

Prompt 1
Build a Node.js CLI setup wizard using the prompts library that asks for project name, framework choice, and whether to add TypeScript, then logs the result.
Prompt 2
How do I inject answers programmatically into prompts for automated testing so the script doesn't wait for keyboard input?
Prompt 3
Create a dynamic prompts chain where a follow-up question only appears if the user selects yes to the previous one.
Prompt 4
Add validation to a prompts text field so users can't submit an empty string or an invalid email address.
Prompt 5
How do I collect answers from multiple prompts at once and use the result object to generate a config file?
Open on GitHub → Explain another repo

← terkelg on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.