Promptly CLI Utility

3.2.0 · active · verified Sun Apr 19

Promptly is a focused Node.js utility for handling command-line input and user interaction. Currently stable at version 3.2.0, it provides a robust `prompt` function with extensive options for input validation, default values, silent input (e.g., for passwords), character replacement, and custom input/output streams. It supports retry logic for failed validations by default and offers timeout functionality. While the release cadence isn't explicitly stated in the provided documentation, its stable 3.x version and continued maintenance on GitHub suggest a steady, albeit perhaps slower, evolution. Its key differentiators lie in its comprehensive validation system with custom error messages and automatic retries, as well as fine-grained control over I/O streams and timeouts, making it suitable for building interactive CLI tools where user input quality is critical. It is primarily used in Node.js environments for CLI applications.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic prompting, input validation with custom error messages, and silent input for sensitive information like passwords, utilizing async/await for clarity.

const promptly = require('promptly');

const validator = function (value) {
    if (value.length < 2) {
        throw new Error('Min length of 2');
    }

    return value;
};

(async () => {
    try {
        console.log('Please enter your name. It must be at least 2 characters long.');
        // Since retry is true by default, promptly will keep asking for a name until it is valid
        // Between each prompt, the error message from the validator will be printed
        const name = await promptly.prompt('Your Name: ', { validator });
        console.log(`Hello, ${name}!`);

        // Example with silent input (for password)
        const password = await promptly.prompt('Enter password (will not show): ', { silent: true, replace: '*' });
        console.log('Password length:', password.length);

    } catch (err) {
        console.error('An error occurred:', err.message);
    }
})();

view raw JSON →