Anderson Green Anderson Green - 1 year ago 47
Node.js Question

Make a Node.js script accept command-line arguments

What is the correct syntax for running a Node.js script with command-line arguments on Linux or Mac?

To run the script with no arguments, I would simply use the command

node stuff.js
, but in this case, I'd like to run a script called
with the arguments
"blah", "hee", "woohoo!"

Answer Source


In summary you'll run it like

node stuff.js blah hee "whoohoo!"

Then your arguments are available in process.argv