Skip to content

Instantly share code, notes, and snippets.

@ianaya89
Created December 4, 2014 02:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ianaya89/19db4bdfb2b2747fdce3 to your computer and use it in GitHub Desktop.
Save ianaya89/19db4bdfb2b2747fdce3 to your computer and use it in GitHub Desktop.
Using Command Line Arguments in Node
//Simple commands: type in console server -f/-g
var units = process.argv[2];
if(units == '-f'){
this.setUnits('Fahrenheit');
} else {
this.setUnits('Celsius');
}
//Flag and Argument Pairs: type in console node -c Tampa,FL
var city;
if(process.argv.indexOf("-c") != -1){ //does our flag exist?
city = process.argv[process.argv.indexOf("-c") + 1]; //grab the next item
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment