args-parser is a minimalist command-line argument parser designed specifically for Node.js environments. Its current stable version is 1.3.0, and it maintains a relatively slow release cadence, reflecting its stable and focused scope. The library directly processes an array of strings, typically `process.argv`, transforming them into a straightforward JavaScript object. Flags are represented as boolean `true` values, while key-value pairs (e.g., `--key=value`) are parsed into string or numeric values accordingly. Its key differentiators include an extremely small footprint and a simple, direct API, making it an ideal choice for basic script argument handling where the overhead or extensive features of more complex parsers like `yargs` or `commander.js` are not required. It explicitly avoids advanced features such as extensive type coercion, positional arguments, aliases, or integrated help generation, focusing solely on efficient, no-frills flag and option parsing.
npm install args-parserVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to install and use `args-parser` to parse simulated command-line arguments, showing the resulting object structure and basic access patterns for flags and key-value options.
For ESM projects, use `const argsParser = require('args-parser');` within a wrapper that uses `createRequire` from the `module` package, or use a tool like Webpack/Rollup for bundling and CJS-to-ESM conversion.For applications requiring advanced CLI features, consider alternative libraries like `yargs`, `commander.js`, or `minimist` combined with custom logic for validation and defaults. If sticking with `args-parser`, implement all validation and defaults manually after parsing.
Always check for `if (args.flag)` instead of `if (args.flag === true)`. Implement default values manually using the logical OR operator or nullish coalescing: `const myFlag = args.flag ?? false;`.
Always explicitly convert string values to the desired type after parsing, for example: `const count = parseInt(args.count, 10);` or `const ratio = parseFloat(args.ratio);`.
Call the required module directly with the arguments array: `const args = require('args-parser')(process.argv);`If running Node.js v12.20.0+, you can use `const { createRequire } = require('module'); const requireCjs = createRequire(import.meta.url); const argsParser = requireCjs('args-parser');`. Otherwise, convert your file to CommonJS or use a bundler.Always check for the existence of the property or provide a fallback value: `const myFlag = args.myFlag ?? false;` or `if (args.myFlag) { /* ... */ }`.No dependency data recorded yet.