Yargs is a Node.js library that parses CLI options and commands and builds help text for interactive command-line programs.
Overview
Yargs is a Node.js library for parsing option strings and structuring command-line applications. It succeeds optimist and helps authors define commands, grouped options, and generated help output rather than hand-writing argument parsing.
Applications can declare subcommands, positional arguments, defaults, and boolean or typed options. Yargs produces a help menu from those definitions and can generate Bash and Zsh completion scripts. Guides cover parsing tricks such as stopping the parser, negated booleans, arrays, objects, and quoted values, plus patterns for multi-command CLIs and custom parser configuration.
TypeScript users can rely on the separate @types/yargs definitions, and examples cover browser environments as well as Node. Installation is via npm as a project dependency, with hideBin recommended to strip the node binary path from process.argv before parsing.
Releases align with Node.js long-term support versions. The current major version requires at least Node v20.19.0, with older majors receiving security updates for a documented period.
Key features
- Commands and grouped CLI options
- Auto-generated help from definitions
- Bash and Zsh completion scripts
- Positional arguments and defaults
- Configurable parser behavior
- TypeScript type definitions via @types
- Browser usage examples in docs
- hideBin helper for process.argv
Use cases
- Building multi-command Node.js CLIs
- Generating --help without manual copy
- Adding shell tab completion to tools
- Parsing complex flags, arrays, and objects
- Standardizing argv handling across scripts