Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

prompt

Package Overview
Dependencies
Maintainers
2
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prompt

A beautiful command-line prompt for node.js

  • 0.1.8
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
471K
decreased by-17.3%
Maintainers
2
Weekly downloads
 
Created

What is prompt?

The 'prompt' npm package is a powerful tool for creating command-line interfaces (CLI) that can interact with users by asking questions and receiving input. It supports various types of prompts, validation, and asynchronous operations.

What are prompt's main functionalities?

Basic Prompt

This feature allows you to prompt the user for basic input. The example code asks for a username and email, then logs the input to the console.

const prompt = require('prompt');
prompt.start();
prompt.get(['username', 'email'], function (err, result) {
  if (err) { return onErr(err); }
  console.log('Command-line input received:');
  console.log('  Username: ' + result.username);
  console.log('  Email: ' + result.email);
});
function onErr(err) {
  console.log(err);
  return 1;
}

Validation

This feature allows you to validate user input based on a schema. The example code ensures that the age input is a number.

const prompt = require('prompt');
prompt.start();
const schema = {
  properties: {
    age: {
      pattern: /^[0-9]+$/,
      message: 'Age must be a number',
      required: true
    }
  }
};
prompt.get(schema, function (err, result) {
  if (err) { return onErr(err); }
  console.log('Command-line input received:');
  console.log('  Age: ' + result.age);
});
function onErr(err) {
  console.log(err);
  return 1;
}

Asynchronous Prompts

This feature allows you to handle prompts asynchronously using async/await. The example code prompts for a username and email, then logs the input.

const prompt = require('prompt');
prompt.start();
async function getUserInput() {
  try {
    const result = await prompt.get(['username', 'email']);
    console.log('Command-line input received:');
    console.log('  Username: ' + result.username);
    console.log('  Email: ' + result.email);
  } catch (err) {
    console.error(err);
  }
}
getUserInput();

Other packages similar to prompt

FAQs

Package last updated on 12 Sep 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc