I call my node.js application with
node index.js a=5
I want to use the value '5' directly as an environment variable in my code like
const myNumber = process.env.a
(like stated here).
If I try the above, 'MyNumber' is undefinded on runtime.
a=5 node index.js
$env:a="5";node index.js
When doing node index.js a=5, a=5 is an argument for node, as index.js is.
If you want to pass an environment variable, you must specify it before node command : a=5 node index.js.
The node process.env is populated with your bash environment variables.
a=5 is an argument to your script not an environment variable. to access the argument in the script use process.argv
https://nodejs.org/en/knowledge/command-line/how-to-parse-command-line-arguments/
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