
Company News
Socket Joins New OpenJS Program to Fund Node.js Security Work
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.
CLI arguments parser for node.js, with sub-commands support. Port of python's argparse (version 3.14.6).
Difference with original.
new ArgumentParser({ description: 'example', add_help: true }).int, float, ...
.add_argument('-b', { type: 'int', help: 'help' }).%r format specifier uses require('util').inspect().See the complete list of differences from Python. Users upgrading from v2 should read the migration guide.
Following code is a JS program that takes a list of integers and produces either the sum or the max:
const { ArgumentParser } = require('argparse')
const parser = new ArgumentParser({ description: 'Process some integers.' })
let sum = ints => ints.reduce((a, b) => a + b)
let max = ints => ints.reduce((a, b) => a > b ? a : b)
parser.add_argument('integers', { metavar: 'N', type: 'int', nargs: '+',
help: 'an integer for the accumulator' })
parser.add_argument('--sum', { dest: 'accumulate', action: 'store_const',
const: sum, default: max,
help: 'sum the integers (default: find the max)' });
let args = parser.parse_args()
console.log(args.accumulate(args.integers))
Assuming the JS code above is saved into a file called prog.js, it can be run at the command line and provides useful help messages:
$ node prog.js -h
usage: prog.js [-h] [--sum] N [N ...]
Process some integers.
positional arguments:
N an integer for the accumulator
options:
-h, --help show this help message and exit
--sum sum the integers (default: find the max)
When run with the appropriate arguments, it prints either the sum or the max of the command-line integers:
$ node prog.js 1 2 3 4
4
$ node prog.js 1 2 3 4 --sum
10
If invalid arguments are passed in, it will issue an error:
$ node prog.js a b c
usage: prog.js [-h] [--sum] N [N ...]
prog.js: error: argument N: invalid 'int' value: 'a'
This is an example ported from Python. You can find detailed explanation here.
Since this is a port with minimal divergence, there's no separate documentation. Use original one instead, with notes about difference.
Commander is another popular npm package for command-line interfaces. It provides a high-level way to specify commands and options, and it automatically generates help messages. Commander is known for its simplicity and declarative style of defining command-line options.
Yargs is a node.js library that helps build interactive command-line tools, by parsing arguments and generating an elegant user interface. It comes with features like command chaining, automatic help generation, and more. Yargs is often praised for its fluent API and its support for advanced features like command-specific configurations.
Minimist is a minimalistic argument parsing library. It is designed to be simple and straightforward, with fewer features than argparse, commander, or yargs. It is a good choice for those who need something lightweight without the need for complex command-line interfaces.
FAQs
CLI arguments parser. Native port of python's argparse.
The npm package argparse receives a total of 231,943,167 weekly downloads. As such, argparse popularity was classified as popular.
We found that argparse demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.

Company News
Socket is joining the OpenJS Security Stewardship Program to fund Node.js vulnerability research, maintainer remediation, and security releases.

Security News
Two compromised GitHub Actions were re-enabled with malicious tags intact, exposing thousands of downstream repositories to Mini Shai-Hulud.

Research
/Security News
A malicious Firefox extension fetches its payload after installation to evade detection, steal Google session cookies, and automate account takeover.