- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
process.argv() Method in Node.js
The process.argv() method is used for returning all the command-line arguments that were passed when the Node.js process was being launched. The first element will always contains the same value as process.execPath.
Syntax
process.argv()
Parameters
Since it returns all the command line arguments passed before the node.js process. It does not need any inputs from the user.
Example
Create a file with name – argv.js and copy the below code snippet. After creating file, use the following command to run this code as shown in the example below −
node argv.js
argv.js
// Node.js program to demonstrate the use of process.argv // Importing the process module const process = require('process'); // Printing property value for process.argv console.log(process.argv);
Output
C:\home
ode>> node argv.js [ '/usr/bin/node', '/home/node/test/process.js' ]
Example
Let's take a look at one more example.
// Node.js program to demonstrate the use of process.argv // Importing the process module const process = require('process'); // Printing process.argv property value var args = process.argv; console.log("Total number of arguments are: "+args.length); args.forEach((val, index) => { console.log(`${index}: ${val}`); });
Output
C:\home
ode>> node argv.js Total number of arguments are: 2 0: /usr/bin/node 1: /home/node/test/process.js
Advertisements