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]
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With