{"id":16140,"library":"node-getopt","title":"node-getopt: Command Line Argument Parser","description":"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.","status":"abandoned","version":"0.3.2","language":"javascript","source_language":"en","source_url":"https://github.com/jiangmiao/node-getopt","tags":["javascript","getopt","arg","parser"],"install":[{"cmd":"npm install node-getopt","lang":"bash","label":"npm"},{"cmd":"yarn add node-getopt","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-getopt","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The primary way to import is using CommonJS `require()`. It exports the `Getopt` class directly.","wrong":"import Getopt from 'node-getopt';","symbol":"Getopt","correct":"const Getopt = require('node-getopt');"},{"note":"The `create` factory method is accessed directly from the `require` call, providing a convenient way to instantiate and define options in one step.","wrong":"import { create } from 'node-getopt';","symbol":"create","correct":"const getopt = require('node-getopt').create([ /* ... */ ]);"},{"note":"`parseSystem()` is an instance method of a `Getopt` object, not a static method. It automatically parses `process.argv.slice(2)`.","wrong":"Getopt.parseSystem();","symbol":"parseSystem","correct":"opt.parseSystem();"}],"quickstart":{"code":"const Getopt = require('node-getopt');\n\n// Create a Getopt instance with option definitions\nconst opt = Getopt.create([\n  ['s' , ''                    , 'short option.'],\n  [''  , 'long'                , 'long option.'],\n  ['S' , 'short-with-arg=ARG'  , 'option with argument', 'S'],\n  ['L' , 'long-with-arg=ARG'   , 'long option with argument'],\n  [''  , 'color[=COLOR]'       , 'COLOR is optional'],\n  ['m' , 'multi-with-arg=ARG+' , 'multiple option with argument'],\n  [''  , 'no-comment'],\n  ['h' , 'help'                , 'display this help'],\n  ['v' , 'version'             , 'show version']\n])\n.bindHelp(); // Bind the 'help' option to display usage information\n\n// Parse command line arguments from process.argv\nconst parsed = opt.parseSystem();\n\nconsole.log('Parsed Options:', parsed.options);\nconsole.log('Remaining Arguments:', parsed.argv);\n\n/*\nTo run:\n  node your-script-name.js foo -s --long-with-arg bar -m a -m b -- --others\n\nExample Output:\n  Parsed Options: { 'short-with-arg': 'S', s: true, 'long-with-arg': 'bar', 'multi-with-arg': [ 'a', 'b' ], S: 'S', L: 'bar', m: [ 'a', 'b' ] }\n  Remaining Arguments: [ 'foo', '--others' ]\n*/","lang":"javascript","description":"Demonstrates how to define command-line options, parse system arguments, and access the parsed options and remaining arguments using node-getopt."},"warnings":[{"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.","message":"This 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.","severity":"breaking","affected_versions":">=0.1.0"},{"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.","message":"The 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.","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"There 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.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"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.","cause":"Attempting to use `require('node-getopt')` in an ES module file where `require` is not globally available.","error":"TypeError: require is not a function"},{"fix":"Install the package using `npm install node-getopt` or `yarn add node-getopt`.","cause":"The `node-getopt` package is not installed or not resolvable from the current execution environment.","error":"Error: Cannot find module 'node-getopt'"}],"ecosystem":"npm"}