Where server.js is my code. Node.js help says this is possible:
var args = process.argv.slice(2);
Note that the first arg is usually the path to nodejs, and the second arg is the location of the script you're executing.
The up-to-date right answer for this it to use the minimist library. We used to use node-optimist but it has since been deprecated. Here is an example of how to use it taken straight from the minimist documentation:
Optimist (node-optimist)Check out optimist library , it is much better than parsing command line options by hand.UpdateOptimist is deprecated. Try yargs which is an active fork of optimist.
Several great answers here, but it all seems very complex. This is very similar to how bash scripts access argument values and it's already provided standard with node.js as MooGoo pointed out. (Just to make it understandable to somebody that's new to node.js) Example: