Created
December 4, 2014 02:43
-
-
Save ianaya89/19db4bdfb2b2747fdce3 to your computer and use it in GitHub Desktop.
Using Command Line Arguments in Node
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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