How do I pass command line arguments to the Node.js program?

Answer

process.argv is an array containing the command line arguments.
The first element will be 'node', the second element will be the name of the JavaScript file. The next elements will be any additional command line arguments.

Example by code:-

// print process.argv


process.argv.forEach(function (val, index, array) {
console.log(index + ': ' + val);
});
This will generate:

$ node process-2.js one two=three four
0: node
1: /Users/mjr/work/node/process-2.js
2: one
3: two=three
4: four

All node.js Questions

Ask your interview questions on node-js

Write Your comment or Questions if you want the answers on node-js from node-js Experts
Name* :
Email Id* :
Mob no* :
Question
Or
Comment* :
 





Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website. If you are using this website then its your own responsibility to understand the content of the website

--------- Tutorials ---