mcuong mcuong - 2 years ago 115
Node.js Question

Nodejs 6.2 self executed script arguments

I can't pass the arguments to my

script below:

#!/usr/bin/env node


When I run
test.js a1 a2 a3
in terminal, I got

Answer Source

You want to use process.argv.

For your example code, it shows the following:

$ ./test.js a1 a2 a3
[ '/usr/local/bin/node', '/private/tmp/test.js', 'a1', 'a2', 'a3' ]
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download