The process.argv property
is an inbuilt application programming interface of the process module which is used to get the arguments passed to the node.js process when run in the command line.
process.argv
This property returns
an array
containing the arguments passed to the process when run it the command line. The first element is theprocess execution path
and the second element isthe path for the js file.
const process = require('process');
console.log(process.argv);
node index.js extra_argument1 extra_argument2 3
[
'C:\\Program Files\\nodejs\\node.exe',
'C:\\nodejs\\g\\process\\argv_1.js',
'extra_argument1',
'extra_argument2',
'3'
]
const process = require('process');
var args = process.argv;
console.log('number of arguments is "+args.length);
args.forEach((val, index) => {
console.log(`${index}: ${val}`);
});
node index.js extra_argument1 extra_argument2 3
number of arguments is 5
0: C:\Program Files\nodejs\node.ext
1: C:\nodejs\g\process\argv_2.js
2: extra_argument1
3: extra_argument2
4: 3