process.argv in node code example

Example 1: node run parameters

var args = process.argv.slice(2);

Example 2: process.argv

>>node myprogram.js firstarg secondarg

process.argv[0] == "node"

process.argv[1] == "myprogram.js"

process.argv[2] == "firstarg"

process.argv[3] == "secondarg"

//process.argv[0] same as process.argv.slice(0)

Example 3: process.argv[2] node js

>>node myprogram.js firstarg secondarg

process.argv[0] == "node"

process.argv[1] == "myprogram.js"

process.argv[2] == "firstarg"

process.argv[3] == "secondarg"

//process.argv[0] same as process.argv.slice(0)

Tags:

Misc Example