npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

inquisitive

v0.1.1

Published

Inquirer middleware engine.

Readme

inquisitive

Build Status Coverage Status

Inquirer middleware engine. Create interactive cli prompts with a middleware engine for handling individual answers.

Example

import 'babel-register'; // enable async/await
import inquisitive from 'inquisitive';
import delay from 'delay';

const inq = inquisitive();

// define a prompt with a middleware handler
inq.use((prompt) => {
    // ask a question
    prompt({
        name: 'name',
        message: 'What is your name',
    });

    // handle the answers
    return async (answers, status, next) => {
        if (answers.name !== 'Nicolas Cage') {
            throw new Error('Legends only');
        }
        await delay(1000);
        await next(); // go to next handler
    };
});

inq.run(); // start asking

Installation

NPM

npm install --save inquisitive

Yarn

yarn add inquisitive

Setup

Inquisitive uses async/await, until this is available for production it is recommended to transpile with Babel.

Use the transform plugin, babel-plugin-transform-async-to-generator.

Usage

Middleware

The concept of middleware in inquisitive is slightly different than common patterns like in Express or Koa. A middleware function is invoked immediately.

Middleware functions have two jobs, ask questions and handle answers. Both of which are optional.

Questions

Middleware functions will be given a prompt function as it's only argument. This prompt function should be called to add questions to inquirer.

inq.use((prompt) => {
    // ask anything
    prompt({
        name: 'first',
        message: 'What is your first name:',
    });
    // and many more...
    prompt({
        name: 'last',
        message: 'What is your last name:',
    });
});

Asking questions is completely optional. In some cases only an answers handler is required as prior middleware may have asked all the questions.

Questions Format

See inquirer Questions.

Answers Handler

Once inquirer has complete the answers it will run through the answer handlers. To give a handler to inquisitive just return an async function from the middleware function.

Answer handler functions take 3 arguments, answers, status and next.

inq.use((prompt) => {
    // ask questions?
    return async (answers, status, next) => {
        status('checking something'); // update spinner text
        doSomething(answers.foo); // handle answers
        await next(); // don't forget to move next
    };
});

Handling answers is also optional. Some middleware may just want to ask questions and have another middleware handle the answers.

Running Cli

To run the interactive prompt call #run() on the inquisitive instance. run also takes a few options to control how inquisitive will report to the terminal.

inq.run({
    args: true,       // read cli args and set question default values
    spinner: true,    // enable/disable spinner
    time: true,       // enable/disable time message at end
});

Args Defaults

Inquisitive has the ability to read args from the terminal and set them as the defaults for questions. This is a convenience options enabled by default.

cli.js

inq.use((prompt) => {
    prompt({
        name: 'name',
        message: 'What is your name:',
    });
});
inq.run();
node cli.js --name "Nicolas Cage"
? What is your name: (Nicolas Cage) _

Custom Inquirer

It is also possible to give a custom built inquirer module to inquisitive. Just pass it into the factory method when creating an instance.

import inquirer from 'inquirer';
import inquisitive from 'inquisitive';

const custom = inquirer.createPromptModule();
// apply customisations
const inq = inquisitive(custom);

API

inquisitive([module])
  • module: Function Custom inquirer module.

Returns inquisitive instance.

Instance

#use(fn)
  • fn: Function Middleware function to add to instance.
#run([opts])
  • otps: Object Run options.
    • opts.args: Boolean Enable/disable argument defaults.
    • opts.spinner: Boolean Enable/disable spinner.
    • opts.time: Boolean Enable/disable time feedback on success.

Returns Promise, resolving answers.

License

BSD-3-Clause

Copyright (c) 2016 9Technology