Getopts
Fast, dependency-free CLI argument parser for Node.js
Repository Health
Technical Analysis
Getopts is a lightweight drop-in replacement for minimist and similar CLI argument parsers. At roughly 180 lines of code with zero dependencies, it breaks up process.argv into a plain key-value object, following the POSIX/GNU utility conventions that most command-line tools already expect.
It supports short options, grouped short flags, long options, aliases, boolean coercion, string coercion, default values, and a stopEarly mode for passing through remaining arguments untouched. The project advertises up to 6x faster parsing than comparable libraries, making it a common choice for CLI tools that want minimist-style ergonomics without the dependency weight.
What You Get
- A single
getopts(argv, options)function with no runtime dependencies - Support for short options, grouped short flags (
-ab=>{a:true,b:true}), and long options - Alias, boolean, string, and default-value configuration per option
- A
stopEarlymode to stop parsing at the first operand and pass through the rest - Both ESM (
index.js) and CommonJS (index.cjs) builds
Common Use Cases
- Parsing arguments in a custom Node.js CLI tool without pulling in a heavier dependency
- Replacing
minimistin an existing project for faster parsing with a compatible API shape - Building small build scripts or task runners that need simple flag/option handling
Under The Hood
Architecture The entire library lives in a single index.js file (~180 lines) that exports one function. It walks the input argv array once, classifying each token as a short option, long option, or operand, and accumulates results into a plain object keyed by option name plus an _ array for positional operands. Tech Stack Zero runtime dependencies; the package ships both an ESM entry (index.js) and a generated CommonJS build (index.cjs) produced by a small build script in package.json, plus TypeScript type declarations (index.d.ts). Code Quality Test coverage is organized by feature area (tests/short.test.js, long.test.js, alias.test.js, boolean.test.js, stopEarly.test.js, unknown.test.js, etc.) using the twist test runner with c8 for coverage, giving each parsing rule its own focused test file. API Design The API is a single function call with a plain options object (alias, boolean, string, default, stopEarly, unknown), requiring no setup or class instantiation, which keeps integration into any CLI script to one line.
Used by 3 apps in this directory
Another Redis Desktop Manager
Developer Tools · Databases
Fast, stable Redis GUI with cluster, SSH, and massive key support
Kibana
Analytics · Monitoring
Your open source window into the Elastic Stack — query, visualize, and act on data stored in Elasticsearch with real-time dashboards, AI-assisted search, and automated alerting.
Penpot
Design Tools
Open-source design platform with GPU-accelerated canvas, native design tokens, and MCP-powered AI workflows for teams that ship fast.