cli-prompt: Tiny CLI Prompter

0.6.0 · abandoned · verified Wed Apr 22

cli-prompt is a lightweight utility designed for creating interactive command-line prompts in Node.js applications. It provides a simple, callback-based API for collecting user input, including basic text prompts, hidden password input, and multi-question sequences. Despite its functionality, the package is considered abandoned, with its last known publication being `0.6.0` over 10 years ago and no significant updates or active maintenance since 2013. This project distinguishes itself through its minimal footprint and straightforward API, contrasting with more modern, promise-based or feature-rich prompt libraries that offer advanced validation, styling, and asynchronous patterns. Due to its abandonment, developers should consider its lack of ongoing support and potential compatibility or security issues.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use `prompt.multi` to collect several types of user input, including text with a default, a password with validation, a number, and a boolean.

const prompt = require('cli-prompt');

console.log('Welcome! Please answer a few questions.');
prompt.multi([
  {
    key: 'username',
    label: 'Enter your desired username',
    default: 'guest_user'
  },
  {
    label: 'Enter your password (min 5 chars)',
    key: 'password',
    type: 'password',
    validate: function (val) {
      if (val.length < 5) {
        throw new Error('Password must be at least 5 characters long');
      }
    }
  },
  {
    label: 'How many pets do you have?',
    key: 'pets',
    type: 'number',
    default: function () {
      // Example of dynamic default based on previous input
      return this.password ? this.password.length : 0;
    }
  },
  {
    label: 'Do you agree to the terms? (yes/no)',
    key: 'agree',
    type: 'boolean'
  }
], function (result) {
  console.log('\nThank you for your input:');
  console.log(JSON.stringify(result, null, 2));
  process.exit(0);
}, function (err) {
  console.error('\nAn error occurred during prompting: ' + err);
  process.exit(1);
});

view raw JSON →