process.argv is a property in Node.js that contains an array of command-line arguments passed to the Node.js process when it was launched.
For example, if you run the following command in the terminal:
The process.argv array would be:
You can use process.argv to access and process command-line arguments in your Node.js program. This is a Node.js program that retrieves the third element of the process.argv array (index 2) and assigns it to the nameArg variable. If there is no third element, it defaults to the string 'world'. Then, the program uses string interpolation to output a message to the console, which includes the value of nameArg.
For example, if you run the following command in the terminal:
The output would be:
Hello Joes!
If you run the following command instead:
The output would be:
Hello world!
This program is a simple example of how to use command-line arguments in a Node.js program to customize its behavior.
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions