Skip to content

Instantly share code, notes, and snippets.

@kevinchisholm
Last active January 8, 2018 00:10
Show Gist options
  • Save kevinchisholm/6196ed643f05bff0c97b80aeeecf3354 to your computer and use it in GitHub Desktop.
Save kevinchisholm/6196ed643f05bff0c97b80aeeecf3354 to your computer and use it in GitHub Desktop.
console.dir(process.argv);
node showArgs-1.js
[
'node',
'/[PATH TO]/showArgs-1.js'
]
console.dir(process.argv);
node showArgs-1.js arg2 arg3 arg4
[
'node',
'/[PATH TO]/showArgs-1.js',
arg2,
arg3,
arg4
]
//omit the first two argument (node and the path to showArgs-2.js)
var args = process.argv.slice(2);
//inspect the arguments
console.dir(args);
node showArgs-2.js arg0 arg1 arg2
[ 'arg0', 'arg1', 'arg2' ]
//omit the first two argument (node and the path to showArgs-3.js)
var args = process.argv.slice(2);
//inspect the arguments
args.forEach(function(val, index, array) {
console.log('Argument # ' + index + ': ' + val);
});
node showArgs-3.js arg0 arg1 arg2
Argument # 0: arg0
Argument # 1: arg1
Argument # 2: arg2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment