mcuong mcuong - 6 months ago 15
Node.js Question

Nodejs 6.2 self executed script arguments

I can't pass the arguments to my

test.js
script below:

#!/usr/bin/env node

console.log(process.execArgv)


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

Answer

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' ]
Comments