options-parser is a lightweight, full-featured command-line argument parser for Node.js, designed with no external dependencies for a minimal footprint. The current stable version is 0.4.0, indicating it's still in active development, likely with a focus on stability before a 1.0 release. Its key differentiators include built-in type validation for common types (like files), automatic help screen generation with customizable formatting, and robust handling of multi-value options and default values. It provides a structured way to define expected command-line flags and arguments, distinguishing between required, optional, and flag-only parameters, making it suitable for scripting and CLI tool development in Node.js environments.
npm install options-parserVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to define a comprehensive set of command-line options including required fields, flags, default values, multi-value options, and type validation. It then parses a simulated argument array, logs the resulting structured data, and showcases the package's ability to automatically generate a formatted help screen.
Pass an `error` callback function as the second or third argument to `options.parse(opts, argv?, error?)` to handle errors programmatically, e.g., `options.parse(opts, (err) => console.error(err.message));`.
Ensure logical consistency in option definitions. For flags, omit `default`. For required options, `default` should only be considered if the 'required' state implies a non-null default, which can be confusing. Typically, remove `default` from `required: true` options.
Always explicitly define `flag: true` or `flag: false` for options, especially when using `showHelp`, to ensure the parser behaves as expected regarding value expectations.
Consult the `options-parser` GitHub repository for release notes and changelogs before upgrading to new minor versions (e.g., 0.4.x to 0.5.x) to identify and adapt to any potential API changes.
Add `const options = require('options-parser');` at the top of your file to import the module.Ensure you are using `const options = require('options-parser');` and accessing `options.parse` as a method on the `options` object.Supply the missing required option in the command line (e.g., `--user=yourname`) or adjust your option definition if it's not truly required for all use cases.
Either define the `unrecognized-flag` option in your `opts` configuration object, or ensure that only expected and defined options are passed on the command line.
No dependency data recorded yet.