A fork of a simple zero dependency command line argument parser for Node.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Corey Hart d5547ac9ef Fixing test runner badge 8 months ago
.github/workflows README cleanup and moving tests to github actions 8 months ago
build README cleanup and moving tests to github actions 8 months ago
lib -Adding test suite 11 years ago
test Upgrading packages munit:0.0.7, nlint:0.0.6 10 years ago
.gitignore -Upgrading munit and nlint packages 11 years ago
.nlint.json Upgrading packages munit:0.0.7, nlint:0.0.6 10 years ago
CHANGELOG.md Releasing v0.0.2 11 years ago
LICENSE README cleanup and moving tests to github actions 8 months ago
README.md Fixing test runner badge 8 months ago
index.js -Initial commit 11 years ago
package-lock.json README cleanup and moving tests to github actions 8 months ago
package.json Added onset docs 8 months ago


NPM version Test Runner Code Climate


argv is a simple, zero dependency, command line argument parser for NodeJS. For a more feature-full CLI parser, checkout Commander.js or Yargs


$ npm install argv


var argv = require( 'argv' );
var args = argv.option( options ).run();
-> { targets: [], options: {} }


Runs the argument parser on the global arguments. Custom arguments array can be used by passing into this method

// Parses default arguments 'process.argv.slice( 2 )'

// Parses array instead
argv.run(["--option=123", "-o", "123"]);


argv is a strict argument parser, which means all options must be defined before parsing starts.

  name: "option",
  short: "o",
  type: "string",
  description: "Defines an option for your script",
  example: "'script --option=value' or 'script -o value'",
  onset: function (args) {
    args; // Object of current arguments parsed


Modules are nested commands for more complicated scripts. Each module has it's own set of options that have to be defined independently of the root options.

	mod: 'module',
	description: 'Description of what the module is used for',
	options: [ list of options ]


Types convert option values to useful JS objects. They are defined along with each option.

  • string: Ensure values are strings
  • path: Converts value into a fully resolved path.
  • integer | int: Converts value into an integer
  • float: Converts value into a float number
  • boolean | bool: Converts value into a boolean object. 'true' and '1' are converted to true, everything else is false.
  • csv: Converts value into an array by splitting on comma's.
  • list: Allows for option to be defined multiple times, and each value added to an array
  • [list|csv],[type]: Combo type that allows you to create a list or csv and convert each individual value into a type.
		name: 'option',
		type: 'csv,int'
		name: 'path',
		short: 'p',
		type: 'list,path'

// csv and int combo
$ script --option=123,456.001,789.01
-> option: [ 123, 456, 789 ]

// list and path combo
$ script -p /path/to/file1 -p /path/to/file2
-> option: [ '/path/to/file1', '/path/to/file2' ]

You can also create your own custom type for special conversions.

argv.type( 'squared', function( value ) {
	value = parseFloat( value );
	return value * value;

	name: 'square',
	short: 's',
	type: 'squared'

$ script -s 2
-> 4


Defining the scripts version number will add the version option and print it out when asked.

argv.version( 'v1.0' );

$ script --version


Custom information can be displayed at the top of the help printout using this method

argv.info( 'Special script info' );

$ script --help

Special script info

... Rest of Help Doc ...


If you have competing scripts accessing the argv object, you can clear out any previous options that may have been set.

argv.clear().option([new options()]);


argv injects a default help option initially and on clears. The help() method triggers the help printout.