Retrieve command-line arguments
If you run node index.js arg1 arg2
, you can retrieve these incoming command line arguments using
var arg1 = process.argv[2], |
The list of commands executed is accessible from the process global object.
argv
stands for arguments vector and is an array. It contains node
and index.js
(or your entry file path equivalent) as its first two values.
Retrieve node-specific command line options
If you run node --harmony index.js arg1
, the --harmony
flag will no be included in process.argv
If you wish to retrieve it, use process.execArgv
. The execArgv array will not include the values already included in process.argv
.
So based on the above command:
process.execArgv will be equal to
['--harmony']
and process.argv will be equal to
['node', '/Users/username/test.js', 'arg1']