Accessing Command Line Arguments
The process.argv
property provides access to the command-line arguments passed to the NodeJS process when it was started. It is an array where the first element (process.argv[0]
) is the path to the NodeJS executable, the second element (process.argv[1]
) is the path to the JavaScript file being executed, and subsequent elements are the command-line arguments.
console.log(process.argv);
// Output: ['node', '/path/to/your/script.js', 'arg1', 'arg2', ...]
What is the purpose of the process object in Node JS ?
In NodeJS, the process
object is a global object that provides access to information and control over the current NodeJS process. It offers various properties and methods to interact with the underlying operating system environment and manage the NodeJS process effectively. Let’s explore the primary purposes of the process
object in NodeJS.