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 🙏

© 2025 – Pkg Stats / Ryan Hefner

expose-cli

v0.0.2

Published

Make your function runnable from CLI

Downloads

7

Readme

  expose-cli

Simple Way To Run Your Local Function From CLI

node index.js localFunction arg1 arg2 arg3

Installation

# NPM
npm i expose-cli

# Yarn
yarn add expose-cli

Example Usage

index.js

const exposeCli = require('./index');

function printSync() {
  console.log('Printed from `printSync`');
}

async function printAsync() {
  console.log('Printed from `printAsync`');
}

function printPromise() {
  return new Promise(resolve => {
    console.log('Printed from `printPromise`');
    resolve();
  });
}

const printClosure = () => {
  console.log('Printed from `printClosure`');
};

function printSyncWithArg(arg1) {
  console.log(`Printed from \`printSyncWithArg\` with arg1: ${arg1}`);
}

async function printAsyncWithArg(arg1) {
  console.log(`Printed from \`printAsyncWithArg\` with arg1: ${arg1}`);
}

function printSyncWithRestArgs(...args) {
  console.log(
    `Printed from \`printSyncWithRestArgs\` with args: ${args.join(', ')}`
  );
}

async function printAsyncWithRestArgs(...args) {
  console.log(
    `Printed from \`printAsyncWithRestArgs\` with args: ${args.join(', ')}`
  );
}

function returnSync() {
  return 'Returned from `returnSync`';
}

async function returnAsync() {
  return 'Returned from `returnAsync`';
}

function returnPromise() {
  return new Promise(resolve => resolve('Returned from `returnPromise`'));
}

exposeCli(
  {
    printSync,
    printAsync,
    printPromise,
    printClosure,
    printSyncWithArg,
    printAsyncWithArg,
    printSyncWithRestArgs,
    printAsyncWithRestArgs,
    returnSync,
    returnAsync,
    returnPromise
  },
  {
    printReturn: true
  }
);

Run local function

Execute

node index.js printSyncWithArg world

Output

Printed from printSyncWithArg: world

Print all listed handler with command help

Execute command

node index.js printSyncWithArg help

Output

IMPORTANT!

The help command will display an <unreachable> message if you use:

  • Closure function. Ex: () => {}
  • Rest arguments. Ex: function(...args)
  • Function stored in a variable. Ex: const handler= function() {}
  • A method in a Class
  • Anonymous function

Calling Format

exposeCli(handlers, [config])

handlers

Format (Object):

command : handler

  • command: string
  • handler: function or object
    • name: string
    • args: array
    • description: string
    • handler: function

config

{
  // Print returned value from function called
  printReturn: false, // default

  // Trigger process.exit() when finished
  exitOnSuccess: true, // default

  // Trigger process.exit(1) when error
  exitOnError: true, // default

  // cutom log handler
  customConsoleLog: console.log, // default
  customConsoleError: console.error, // default

  // custom command `help` name
  customHelpName: 'help',  // default

  // custom additional command `help` options
  customHelp: {
    handler: defaultHelpHandler,
    name: 'help',
    args: '',
    description: 'Show all the functions listed.'
  }  // default
}

Support

  • Can be used using webpack
  • Supports calling async function or function that return Promise or closure
  • Supports function that throw an error

Change Log

v0.0.2

  • Fixed bugs
  • Added default handler for help
  • Support object format for handlers arguments