Command line arguments

1.Introduction to command line arguments in Node.js

In node.js we have process object which will help us get command line arguments.

process.argv[]

Above array will help us get the arguments.

Example

create a file comline.js in your work folder with your favorite text editor with following content:

// lets print all the command line argument on the console
var argument = "";
for (var i = 0; i < process.argv.length; i++) {
  argument = process.argv[i];
  console.log(argument);
  
}

Lets run the code and see how we get command line parameters

D:\work\nodejs> node comline.js hello world
node
D:\work\nodejs\comline.js
hello
world

It actually starts with the first word which you wrote in your terminal to execute the command. So actually you can modify the logic to start accepting arguments from third element in process.argv[] array.