Skip to content

Instantly share code, notes, and snippets.

@peterhughesdev
Created November 22, 2016 22:38
Show Gist options
  • Save peterhughesdev/93c6a4cd6221746021dc0e86e30fad78 to your computer and use it in GitHub Desktop.
Save peterhughesdev/93c6a4cd6221746021dc0e86e30fad78 to your computer and use it in GitHub Desktop.
Basic usage of commander.js
var commander = require('commander');
commander.version('0.0.1')
.option('-h, --host <n>', 'The hostname', 'localhost')
.option('-p, --port <n>', 'The port', 8080)
.option('-t, --topic <n>', 'The topic', 'foo')
.parse(process.argv);
var host = commander.host
var port = commander.port
var topic = commander.topic
console.log(host, port, topic);
@peterhughesdev
Copy link
Author

peterhughesdev commented Nov 22, 2016

Usage:

node index.js -h some.host.com --port 8081

Should output:

some.host.com 8081 foo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment