Command-line arguments are a common way to parameterize execution of programs. For example, node script.js uses script.js as an argument to the node program.
To experiment with command-line arguments, you can save this code in a file (e.g., command-line-arguments.js) and run it with Node.js:
In JavaScript (Node.js), we use process.argv to access command-line arguments. The first two elements of process.argv are always the path to the Node.js executable and the path to the JavaScript file being executed, respectively. The remaining elements are the additional command-line arguments.
Next, we’ll look at more advanced command-line processing with option parsing libraries in JavaScript.