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

node-menu

v1.3.2

Published

Allows to create command line menu for REPL applications

Downloads

66

Readme

node-menu

This module allows to create console menu for your REPL application. It allows you to register menu items with their handlers. Optionally you may provide handler's owner object and list of arguments being passed to handler.

Installation

npm install node-menu

Methods

var menu = require('node-menu');

Each method returns reference on self object, so calls could be chained.

menu.addItem(title, handler, owner, args)

Add item to the menu. Returns menu for chaining calls.

  • title - title of the menu item;
  • handler - item handler function;
  • owner - owner object of the function (this);
  • args - array of objects argument names being passed to the function, argument is an object with two fields: 'name' and 'type'. Available types are: 'numeric', 'bool' and 'string';
menu.addItem(
    'Menu Item',
    function(str, bool, num1, num2) {
        console.log('String: ' + str);
        if (bool) {
            console.log('bool is true');
        } else {
            console.log('bool is false');
        }
        var sum = num1 + num2;
        console.log('num1 + num2: ' + sum);
    },
    null,
    [
        {'name': 'Str Arg', 'type': 'string'},
        {'name': 'Bool Arg', 'type': 'bool'},
        {'name': 'num1', 'type': 'numeric'},
        {'name': 'num2', 'type': 'numeric'}
    ]);

menu.addDelimiter(delimiter, cnt, title)

Adds delimiter to the menu. Returns menu for chaining calls.

  • delimiter - delimiter character;
  • cnt - delimiter's repetition count;
  • title - title of the delimiter, will be printed in the middle of the delimiter line;

The output of the delimiter:

menu.addDelimiter('-', 33, 'Main Menu')
------------Main Menu------------

menu.addDelimiter('*', 33)
*********************************

menu.enableDefaultHeader()

Turns on default header (turned on by default). Returns menu for chaining calls.

menu.enableDefaultHeader()

menu.disableDefaultHeader()

Turns off default header. No header will be printed in this case. Returns menu for chaining calls.

menu.disableDefaultHeader()

menu.customHeader(customHeaderFunc)

Turns off default header and prints custom header passed in customHeaderFunc. Returns menu for chaining calls.

menu.customHeader(function() {
    process.stdout.write("\nCustom header\n");
})

menu.enableDefaultPrompt()

Turns on default prompt (turned on by default). Returns menu for chaining calls.

menu.enableDefaultPrompt()

menu.disableDefaultPrompt()

Turns off default prompt. No prompt will be printed in this case. Returns menu for chaining calls.

menu.disableDefaultPrompt()

menu.customPrompt(customPromptFunc)

Turns off default prompt and prints custom header passed in customPromptFunc. Returns menu for chaining calls.

menu.customPrompt(function() {
    process.stdout.write("Custom prompt\n");
})

menu.resetMenu()

Clears all data and listeners from the menu object so the object can be updated and reused.

menu.continueCallback(continueCallback)

Set callback which must be invoked when "Enter" button pressed to continue.

menu.resetMenu()

menu.start()

Start menu.

Example

Live Example

Source

var menu = require('node-menu');

var TestObject = function() {
    var self = this;
    self.fieldA = 'FieldA';
    self.fieldB = 'FieldB';
}

TestObject.prototype.printFieldA = function() {
    console.log(this.fieldA);
}

TestObject.prototype.printFieldB = function(arg) {
    console.log(this.fieldB + arg);
}

var testObject = new TestObject();
var timeout;

menu.addDelimiter('-', 40, 'Main Menu')
    .addItem(
        'No parameters',
        function() {
            console.log('No parameters is invoked');
        })
    .addItem(
        "Print Field A",
        testObject.printFieldA,
        testObject)
    .addItem(
        'Print Field B concatenated with arg1',
        testObject.printFieldB,
        testObject,
        [{'name': 'arg1', 'type': 'string'}])
    .addItem(
        'Sum',
        function(op1, op2) {
            var sum = op1 + op2;
            console.log('Sum ' + op1 + '+' + op2 + '=' + sum);
        },
        null,
        [{'name': 'op1', 'type': 'numeric'}, {'name': 'op2', 'type': 'numeric'}])
    .addItem(
        'String and Bool parameters',
        function(str, b) {
            console.log("String is: " + str);
            console.log("Bool is: " + b);
        },
        null,
        [{'name': 'str', 'type': 'string'}, {'name': 'bool', 'type': 'bool'}])
    .addItem(
        'Long lasting task which is terminated when Enter pressed',
        function(time) {
            console.log("Starting long lasting job for " + time + " sec");
            timeout = setTimeout(function() {
                console.log("Long lasting job is done");
                timeout = undefined;
            }, time * 1000);
        },
        null,
        [{'name': 'Job execution time, sec', 'type': 'numeric'}])
    .addDelimiter('*', 40)
    .continueCallback(function () {
        if (timeout) {
            clearTimeout(timeout);
            console.log("Timeout cleaned");
            timeout = undefined;
        }
    })
    // .customHeader(function() {
    //     process.stdout.write("Hello\n");
    // })
    // .disableDefaultHeader()
    // .customPrompt(function() {
    //     process.stdout.write("\nEnter your selection:\n");
    // })
    // .disableDefaultPrompt()
    .start();

Output of this example:

    _   __            __       __  ___
   / | / /____   ____/ /___   /  |/  /___   ____   __  __
  /  |/ // __ \ / __  // _ \ / /|_/ // _ \ / __ \ / / / /
 / /|  // /_/ // /_/ //  __// /  / //  __// / / // /_/ /
/_/ |_/ \____/ \__,_/ \___//_/  /_/ \___//_/ /_/ \__,_/  v.1.0.0

---------------Main Menu---------------
1. No parameters
2. Print Field A
3. Print Field B concatenated with arg1: "arg1"
4. Sum: "op1" "op2"
5. String and Bool parameters: "str" "bool"
***************************************
6. Quit

Please provide input at prompt as: >> ItemNumber arg1 arg2 ... (i.e. >> 2 "string with spaces" 2 4 noSpacesString true)

>>

To invoke item without arguments just type number and Enter. To invoke item with arguments, type number then arguments delimited with space. If string argument has spaces it must be double quoted.

Additional links

Similar library for other languages: