Learn how to use command-line arguments in your Node.js application

In this article, you will see how to pass command-line arguments to your Node.js application. You will also learn how to access them.

However, before proceeding further, let’s start with some basic stuff.  To run a Node.js application, you run the following command in your terminal:

node index.js

Thus, when you run the above command, you can pass any number of arguments. When it comes to command-line arguments, there are  two types:

  • single arguments such as node index.js myArg
  • key-value arguments such as node index.js myArg=myVal

Now, the next step is to learn how you can access these arguments in your Node.js application.


The process object

In Node.js, the process object is a global object and contains information about the current Node processes. Since it’s a global object, you have access to it directly even though you do not import it into your application.

#node.js #backend #node

Pass Command Line Arguments To Your Node.js App
1.85 GEEK