In Node.js, you can access command line arguments using the process.argv
array. The first element of process.argv
is the path to Node.js executable, the second element is the path to the script file being executed, and the following elements are the arguments passed in.
Here's an example of how you can access command line arguments in Node.js:
index.tsx37 chars3 lines
If you run the script with node app.js arg1 arg2 arg3
, the output will be an array of command line arguments as shown below:
index.tsx80 chars8 lines
You can access specific arguments by their index in the process.argv
array.
gistlibby LogSnag