commander
Complete solution for Node.js command-line interfaces — parse arguments, generate help text, and build complex CLI tools with subcommands.
commander
General JSComplete solution for Node.js command-line interfaces — parse arguments, generate help text, and build complex CLI tools with subcommands.
Fit
Bundle (gzip)
11.1 kB
39.3 kB raw
Install size includes transitive dependencies. Bundle size is gzipped browser payload.
Freshness
The Problem
Parsing CLI arguments manually with process.argv is tedious and error-prone. Handling flags, options, subcommands, variadic arguments, and generating consistent --help output requires significant boilerplate.
What It Does
Commander lets you declare commands, options (with short/long forms), required/optional arguments, and default values declaratively. It generates --help and --version output automatically, validates required options, and supports nested subcommands for complex CLIs.
Installation
npm install commanderUsage Example
import { program } from 'commander';
program
.name('deploy')
.description('Deploy your app to production')
.version('1.0.0');
program
.command('push <environment>')
.description('Push to an environment')
.option('-f, --force', 'Force deployment even with warnings')
.option('--tag <tag>', 'Docker image tag', 'latest')
.action((environment, options) => {
console.log(`Deploying to ${environment} with tag ${options.tag}`);
if (options.force) console.log('Force mode enabled');
});
program.parse(process.argv);Related packages
Unified TypeScript SDK for building AI-powered apps — switch between 20+ LLM providers without rewriting code.
animejsGeneral JSLightweight JavaScript animation library with a tiny footprint and a powerful, expressive API.
AOSGeneral JSAn easy-to-use library that makes elements fade, slide, or zoom into view as the user scrolls down your page.
archiverGeneral JSStreaming interface for generating ZIP and TAR archives in Node.js — create compressed archives programmatically from files, directories, and buffers.
@formkit/auto-animateGeneral JS> Add smooth transitions to any element with a single line — zero-config animations for adds, removes, and moves.