Tuesday, March 4, 2014

Node.js example: get command line arguments

The array process.argv will be passed 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:
console.log('process.argv[0]: ' + process.argv[0]);
console.log('process.argv[1]: ' + process.argv[1]);
console.log('process.argv[2]: ' + process.argv[2]);

console.log("process.argv.length: " + process.argv.length);

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

Node.js example: get command line arguments
Node.js example: get command line arguments

No comments: