Yargs helps you build interactive command-line tools by parsing arguments and generating an elegant user interface.
Basic Usage
const argv = require('yargs').argv;
argv._ // Array of positional arguments: [ ... ]
argv.$0 // Executable name: "node bin/mybin"
argv.verbose // Boolean / string flag value: --verbose
Version & Help Output
const argv = require('yargs')
// Version configuration
.alias('v', 'version')
.version(function() { return require('../package').version; })
.describe('v', 'show version information')
// Help configuration
.alias('h', 'help')
.help('help')
.usage('Usage: $0 -x [num]')
.showHelpOnFail(false, "Specify --help for available options")
Option Configuration
.option('f', {
alias: 'file',
describe: 'Path to target file',
type: 'string', /* 'array' | 'boolean' | 'string' */
nargs: 1,
demand: true,
demand: 'file is required',
default: '/etc/passwd'
// also supports: count: true, requiresArg: true
})
.options({
f: { /* option hash */ }
})
Commands & Examples
.example('$0 -f config.json', 'Run with configuration file')
.epilog('Copyright 2026')
.command('start', 'Start the server application')
Counting & Stacking Flags
.count('verbose')
// Passing -vvv results in:
argv.verbose // => 3
Strict Mode
.strict()
Programmatic Methods
yargs.showHelp()
const helpText = yargs.help() // => string output