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

commonline

v1.0.0

Published

Modern Custom CLI Framework for Node.js without external dependencies

Readme

commonLine

Modern Custom CLI Framework for Node.js. A lightweight, production-ready CLI library with a custom input engine (no readline dependency).

Features

  • ✅ Custom input engine built from scratch (no readline/inquirer/prompts)
  • ✅ Clean, modular architecture
  • ✅ Command registration and execution
  • ✅ Argument parsing with quote support
  • ✅ Graceful error handling
  • ✅ Ctrl+C support
  • ✅ No external dependencies
  • ✅ Fully tested
  • ✅ Production-ready

Installation

npm install commonline

Quick Start

const cl = require('commonline');

cl.createInput('~ $ ');

cl.command('contoh', () => {
  console.log('tes');
});

cl.command('say', (args) => {
  console.log(args.join(' '));
});

cl.start();

Run:

node app.js

Output:

~ $ contoh
tes

~ $ say halo dunia
halo dunia

~ $ 

Usage

Basic Setup

const cl = require('commonline');

// Set custom prompt
cl.createInput('myapp> ');

// Define commands
cl.command('hello', () => {
  console.log('Hello!');
});

// Start CLI
cl.start();

Commands with Arguments

cl.command('greet', (args) => {
  const name = args.join(' ') || 'Guest';
  console.log(`Hello, ${name}!`);
});

cl.command('add', (args) => {
  const sum = args
    .map(n => parseInt(n, 10))
    .filter(n => !isNaN(n))
    .reduce((a, b) => a + b, 0);
  console.log(`Sum: ${sum}`);
});

Usage:

myapp> greet John Doe
Hello, John Doe!

myapp> add 5 10 15
Sum: 30

Quote Support

Arguments with spaces can use quotes:

cl.command('echo', (args) => {
  console.log(args.join(' '));
});

Usage:

myapp> echo "hello world"
hello world

myapp> echo 'single quotes'
single quotes

Command Management

// Check if command exists
if (cl.hasCommand('test')) {
  console.log('Command exists');
}

// Remove command
cl.removeCommand('test');

// Clear all commands
cl.clearCommands();

// Stop CLI
cl.stop();
process.exit(0);

API Reference

createInput(prompt)

Set custom prompt string.

cl.createInput('> ');

command(name, callback)

Register a command with callback.

Callback signature:

(args, context) => {
  // args: string[] - command arguments
  // context: CLIContext - CLI context object
}

Example:

cl.command('test', (args, context) => {
  console.log('Args:', args);
  console.log('Prompt:', context.getPrompt());
});

removeCommand(name)

Remove a registered command.

cl.removeCommand('test');

hasCommand(name)

Check if command is registered.

if (cl.hasCommand('test')) {
  // ...
}

clearCommands()

Remove all registered commands.

cl.clearCommands();

start()

Start the CLI input loop.

cl.start();

stop()

Stop the CLI.

cl.stop();

Architecture

commonLine uses a modular architecture:

CLI (Main)
├── InputEngine (Custom input handling)
│   ├── Terminal (Terminal I/O)
│   ├── LineEditor (Line display)
│   └── KeyHandler (Keyboard events)
├── CommandRegistry (Command storage)
├── CommandParser (Input parsing)
└── CLIContext (State management)

Core Modules

  • CLI.js - Main orchestrator
  • CommandRegistry.js - Command management
  • CommandParser.js - Input parsing
  • CLIContext.js - State/configuration
  • InputEngine.js - Input loop
  • Terminal.js - Terminal I/O
  • LineEditor.js - Line editing
  • KeyHandler.js - Keyboard events
  • Command.js - Individual commands

Examples

See examples/ directory:

  • basic.js - Basic commands
  • arguments.js - Argument handling
  • multiple-commands.js - Complex example

Run examples:

npm run example:basic
npm run example:arguments
npm run example:multiple

Testing

Run all tests:

npm test

Tests cover:

  • Command registration and execution
  • Argument parsing with quotes
  • CLI lifecycle
  • Error handling
  • Command deduplication

Development

Project structure:

commonLine/
├── src/
│   ├── index.js           # Entry point
│   ├── core/              # Core classes
│   ├── input/             # Input engine
│   ├── commands/          # Command classes
│   ├── errors/            # Error classes
│   └── utils/             # Utilities
├── examples/              # Example programs
├── test/                  # Test suite
└── README.md

No External Dependencies

commonLine doesn't use:

  • readline
  • inquirer
  • prompts
  • enquirer
  • Any other CLI library

It uses only Node.js native APIs:

  • process.stdin/stdout
  • Buffer
  • EventEmitter pattern

Keyboard Support

  • Enter - Submit command
  • Backspace - Delete character
  • Ctrl+C - Exit gracefully
  • Ctrl+D - Exit gracefully

Error Handling

Errors are handled gracefully:

cl.command('test', (args) => {
  throw new Error('Something went wrong');
  // Error is caught and logged
});

Performance

  • Zero initialization overhead
  • Minimal memory footprint
  • Direct terminal I/O
  • No buffering overhead

License

MIT

Contributing

Contributions welcome!