Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I obtain system arguments in node.js?

node helloworld.js alex

I want it to console.log() alex. How do I pass "alex" as an argument into the code?

In python ,it is sys.argv[1]

like image 398
TIMEX Avatar asked Jan 01 '26 19:01

TIMEX


1 Answers

You can access command line arguments using process.argv in node.js.

The array also includes the node command and the application file, so the first custom command line argument will have an index = 2.

process.argv[2] === 'alex'; // true

http://nodejs.org/api/process.html#process_process_argv

like image 80
Jørgen Avatar answered Jan 03 '26 10:01

Jørgen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!