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

interactive-cli

v1.1.6

Published

Making it easy to create interactive command line scripts in Node.js

Readme

Interactive CLI for Node.js

The Interactive CLI is a library that makes it easy to create interactive command line scripts in Node.js by utilizing promises.

npm version

Installation

Using npm:

npm i --save interactive-cli

Example interaction:

$ node examples/basic-usage.js --example

Would you like to
a) Create a new user
b) Delete a user
q) Quit
?:  a

Enter user's email
email:  [email protected]

What's the name for the user
firstname:  Leonardo
lastname:  DiCaprio
User Leonardo DiCaprio was created successfully!

All DONE!

Would you like to
a) Create a new user
b) Delete a user
q) Quit
?:  b

Which user would you like to delete?
a) Leonardo DiCaprio
b) Jennifer Lopez
q) Quit
?:  b

Are you absolutely sure?
continue? (y/n):  y
User Jennifer Lopez was successfully deleted!

All DONE!

Would you like to
a) Create a new user
b) Delete a user
q) Quit
?:  q

The Gist

const { promptFields, promptToContinue, promptOptions, startWith, onFinalError, exit, DontContinue } = require('../')

new Promise((resolve, reject) => {
  // Do some preparation, such as getting
  // a reference to a database or authenticating
  resolve({
    createUser: () => Promise.resolve(),
    listUsers: () =>
      Promise.resolve({
        '31725276-73a9-4830-aa77-a86fce4dd7f8': 'Leonardo DiCaprio',
        '53bd3330-4bd7-47c5-a685-f1039e043eae': 'Jennifer Lopez',
      }),
    deleteUser: () => Promise.resolve(),
  })
})
  .then((api) => {
    const initialOptions = {
      createUser: 'Create a new user',
      deleteUser: 'Delete a user',
    }
    const handler = (selection) => {
      switch (selection) {
        case 'createUser':
          return createUser(api)

        case 'deleteUser':
          return deleteUser(api)

        default: {
          throw new ExitScript(`Unknown selection "${selection}"`)
        }
      }
    }

    return startWith('Would you like to', initialOptions, handler)
  })
  .catch(onFinalError)
  .then(exit)

function createUser(api) {
  const user = {}
  return promptFields("Enter user's email", 'email')
    .then((email) => {
      user.email = email
    })

    .then(() => promptFields("What's the name for the user", ['firstname', 'lastname']))
    .then((res) => {
      user.firstname = res.firstname
      user.lastname = res.lastname
    })

    .then(() => {
      return api.createUser(user).catch((err) => {
        throw DontContinue('User could not be created because of error: ' + err.message)
      })
    })

    .then(() => {
      console.log(`User ${user.firstname} ${user.lastname} was created successfully!`)
    })
}

function deleteUser(api) {
  const data = {}
  return api
    .listUsers()
    .then((users) => {
      data.users = users
      return users
    })
    .then((users) => promptOptions('Which user would you like to delete?', users))
    .then((selection) => {
      data.selection = selection
      return selection
    })
    .then((selection) => {
      console.log('\n' + 'Are you absolutely sure?')
      return promptToContinue(selection)
    })
    .then((selection) => {
      api.deleteUser(selection)
    })
    .then(() => {
      console.log(`User ${data.users[data.selection]} was successfully deleted!`)
    })
}

License

MIT