Registry / http-networking / args-parser

args-parser

JSON →
library1.3.0jsnpmunverified

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.

http-networking
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.

The package is CommonJS-only and exports the parsing function directly as its default. It expects `process.argv` or a similar string array as its argument.

const argsParser = require('args-parser'); const args = argsParser(process.argv);

The module's default export is the parsing function itself. There are no named exports available.

const parseArgs = require('args-parser'); const myArgs = parseArgs(['--config=dev', '-v']);

As of v1.3.0, `args-parser` does not ship with TypeScript type definitions. Users will need to declare types manually or rely on 'any'.

// No specific type definitions are shipped with the package, infer 'any' or define locally.

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.

const argsParser = require('args-parser'); // Simulate command-line arguments const simulatedArgs = [ 'node', 'script.js', '--careful', '-dangerous', '--tomatoes=3', '--tonight', '--key=ek==', '--rate=4.5' ]; // In a real script, you'd use: const args = argsParser(process.argv); const args = argsParser(simulatedArgs); console.log('Parsed Arguments:'); console.log(args); if (args.careful) { console.log('Careful flag is set!'); } if (args.tomatoes) { console.log(`Number of tomatoes: ${args.tomatoes}`); // Note: args.tomatoes is a string '3' } if (args.rate) { console.log(`Rate value: ${parseFloat(args.rate)}`); // Type coercion often needed } // Example of accessing an argument that might not exist if (args.verbose === undefined) { console.log('Verbose flag was not provided.'); }
Debug
Known footguns
gotchaThe package is CommonJS-only and does not natively support ES Modules (`import`/`export`) syntax. Attempting to import it directly in an ESM context will result in a runtime error.
gotcha`args-parser` provides a very basic parsing mechanism. It does not include features commonly found in more robust CLI libraries, such as type validation (all values from `--key=value` are strings), default values, aliases, positional arguments, subcommands, or automatic help message generation.
gotchaArguments without an equals sign (`--flag`) are always parsed as `true` if present, and `undefined` if absent. There is no direct way to specify `false` for a flag from the command line, and `args-parser` does not provide an option to set default values for missing flags.
gotchaValues parsed from `--key=value` are always treated as strings. While numbers might appear to parse correctly, they remain string types and require explicit type coercion (e.g., `parseInt`, `parseFloat`) if arithmetic operations or strict type checks are needed.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
19 hits · last 30 days
bytedance
5
gptbot
4
ahrefsbot
4
script
1
googlebot
1
Resources