
yargs
A JavaScript library for building command line tools that parse arguments and generate help menus.
- Stars
- 11.5k
- Forks
- 1.1k
- Licence
- MIT
- Language
- JavaScript
- Last update
- 6 days ago
- Type
- Library
What it is
Yargs is a Node.js library that reads the options and commands a user types into a terminal and turns them into values your program can use. It also builds a help menu automatically from the options you define, and can generate Bash and Zsh completion scripts. Developers use it when they want a command line program with subcommands and flags without writing that parsing code by hand.
- Build a CLI with a serve command that takes a port option, as shown in the README's complex example
- Add a verbose boolean flag with a short alias such as -v
- Generate Bash or Zsh completion scripts for your command
- Provide typed argument parsing in a TypeScript project using @types/yargs
Great for
- Node.js developers building command line tools with subcommands and flags
- Teams who want an automatically generated --help menu
- Developers who need shell completion scripts for their CLI
- Developers who want TypeScript type definitions for argument parsing
Not ideal for
- Non-developers looking for an end-user application, since this is a library you code against
- Projects that do not use Node.js or JavaScript, since the library is written for that ecosystem
- Very simple scripts that only read process.argv directly, where a library adds unnecessary weight
How to get it
- 1
Install with a package manager
You'll need: Node.js (version not specified in the README) · npm
Install yargs with npm
npm i yargsInstall TypeScript type definitions (optional, for TypeScript projects)
npm i @types/yargs --save-dev - 2
Run it
- Install the package with npm i yargs
- Create a script that imports yargs and hideBin from yargs/helpers
- Parse arguments with yargs(hideBin(process.argv)).parse()
- Run your script with flags such as --ships=4 to see the parsed values
- 3
Get the most out of it
- Use .command() to group related actions into subcommands, as in the serve example
- Use .positional() to set defaults and descriptions for positional arguments
- Add aliases such as alias: 'v' to options for short flags
- Read the API, examples, and advanced docs linked from the README for configuration and parser customization
Downloads
Strengths
- Automatically generates a help menu from your option definitions
- Supports commands, grouped options, and shell completion
- Has type definitions available for TypeScript users
Trade-offs
- Requires writing JavaScript or TypeScript code; it is not a ready-made tool to run directly
- The README is short and points to separate docs for the full API and advanced topics
- The README does not state a specific minimum Node.js version; it only says it tracks Node.js release schedules
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.