🛠️
Utility15M+/wkMIT

yargs

Yargs is a feature-rich library for building interactive command-line tools by parsing arguments, generating help text, and providing a comprehensive set of uti

Installation

npm
npm install yargs
yarn
yarn add yargs
pnpm
pnpm add yargs

Import

ESM
import yargs from 'yargs';

Quick Example

usage
import yargs from 'yargs';
import { hideBin } from 'yargs/helpers';

const argv = yargs(hideBin(process.argv))
  .command('serve', 'start server', (y) =>
    y.option('port', { type: 'number', default: 3000 })
  )
  .demandCommand()
  .parse();

About yargs

Yargs is a feature-rich library for building interactive command-line tools by parsing arguments, generating help text, and providing a comprehensive set of utilities for CLI application development. Yargs excels at building complex CLI applications with multiple commands, nested subcommands, positional arguments, typed options with coercion, argument validation, middleware, and auto-generated help and completion scripts. The library supports commands with builder functions that define command-specific options, handlers that execute the command logic, and middleware that runs before handlers for tasks like loading configuration files or checking authentication. Yargs provides .demandOption() for required flags, .choices() for enum-like options, .conflicts() and .implies() for option relationships, .coerce() for type conversion, and .check() for custom validation. The .completion() method generates shell completion scripts for bash, zsh, and fish. Yargs handles configuration from environment variables, config files (JSON/YAML), and package.json fields. The library supports localized help text through a string table system. Yargs is particularly well-suited for complex CLI applications with multiple commands and sophisticated option relationships.

Quick Facts

Packageyargs
CategoryUtility
Weekly Downloads15M+
LicenseMIT
Installnpm install yargs

Related Packages

Browse npm Packages by Category

Explore our reference of 200 popular npm packages with install commands, examples, and quick-start guides.