Registry / node-getopt

node-getopt

JSON →
library0.3.2jsnpmunverified

node-getopt is a minimalist command-line argument parser for Node.js, designed to mimic the traditional `getopt` utility. Currently at version 0.3.2, the package was last updated in 2013, indicating it is an abandoned project and no longer actively maintained. Its primary function is to define and parse both short and long options, supporting mandatory or optional arguments, and handling multiple occurrences of an option. It includes utilities for binding a 'help' option and generating usage messages. Its key differentiator at the time was its simplicity and close adherence to traditional `getopt` semantics for Node.js environments. Due to its age and reliance on very old Node.js versions (>=0.6.0), modern Node.js applications will likely find it incompatible or prefer more contemporary argument parsing libraries that support ESM and TypeScript.

npm install node-getopt
INSTALL
IMPORT
SIG · NODE-GETOPT
N
node-getopt
javascriptv0.3.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Getopt
const Getopt = require('node-getopt');
import Getopt from 'node-getopt';
The primary way to import is using CommonJS `require()`. It exports the `Getopt` class directly.
create
const getopt = require('node-getopt').create([ /* ... */ ]);
import { create } from 'node-getopt';
The `create` factory method is accessed directly from the `require` call, providing a convenient way to instantiate and define options in one step.
parseSystem
opt.parseSystem();
Getopt.parseSystem();
`parseSystem()` is an instance method of a `Getopt` object, not a static method. It automatically parses `process.argv.slice(2)`.

Demonstrates how to define command-line options, parse system arguments, and access the parsed options and remaining arguments using node-getopt.

const Getopt = require('node-getopt'); // Create a Getopt instance with option definitions const opt = Getopt.create([ ['s' , '' , 'short option.'], ['' , 'long' , 'long option.'], ['S' , 'short-with-arg=ARG' , 'option with argument', 'S'], ['L' , 'long-with-arg=ARG' , 'long option with argument'], ['' , 'color[=COLOR]' , 'COLOR is optional'], ['m' , 'multi-with-arg=ARG+' , 'multiple option with argument'], ['' , 'no-comment'], ['h' , 'help' , 'display this help'], ['v' , 'version' , 'show version'] ]) .bindHelp(); // Bind the 'help' option to display usage information // Parse command line arguments from process.argv const parsed = opt.parseSystem(); console.log('Parsed Options:', parsed.options); console.log('Remaining Arguments:', parsed.argv); /* To run: node your-script-name.js foo -s --long-with-arg bar -m a -m b -- --others Example Output: Parsed Options: { 'short-with-arg': 'S', s: true, 'long-with-arg': 'bar', 'multi-with-arg': [ 'a', 'b' ], S: 'S', L: 'bar', m: [ 'a', 'b' ] } Remaining Arguments: [ 'foo', '--others' ] */
Debug
Known issues
breakingThis package is CommonJS-only and does not provide ES module exports. Attempting to `import` it in an ES module environment will result in a runtime error.
fix
Use `const Getopt = require('node-getopt');` in CommonJS modules. For ES module projects, consider using a more modern argument parsing library or a CJS-to-ESM wrapper if absolutely necessary.
affects: >=0.1.0
gotchaThe package has not been updated since 2013 (version 0.3.2) and targets Node.js versions >=0.6.0. It is unlikely to be compatible with modern Node.js features or best practices without significant issues or security concerns.
fix
It is strongly recommended to use a currently maintained and actively developed command-line argument parser for any new or existing projects. This package should be considered for historical reference only.
affects: >=0.1.0
gotchaThere are no TypeScript type definitions available for `node-getopt` (neither bundled nor on `@types/node-getopt`). This means TypeScript projects will lack type safety and autocompletion when using this library.
fix
If you must use this package in a TypeScript project, you will need to manually declare its types (e.g., `declare module 'node-getopt';`) or accept the lack of type safety. This further underscores the recommendation to use modern alternatives.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: require is not a function
Attempting to use `require('node-getopt')` in an ES module file where `require` is not globally available.
fix
Ensure your file is treated as a CommonJS module (e.g., by using `.cjs` extension or `"type": "commonjs"` in `package.json`). Or, preferably, migrate to a modern CLI parser that supports ESM.
Error: Cannot find module 'node-getopt'
The `node-getopt` package is not installed or not resolvable from the current execution environment.
fix
Install the package using `npm install node-getopt` or `yarn add node-getopt`.
Upgrade
Version history
0.3.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
node-getopt — npm install node-getopt · libregistry