I am setting a variable in Express.js as follows: app.set('HOST', 'demo.sample.com');
. However, if I try to read this variable, I get undefined
as the output. I am reading the variable using process.env.HOST
. Nevertheless, if I try to read it using app.get('HOST')
, I get the correct value.
I cannot use app.get('HOST')
since I am reading the variable in another file too — a file that does not contain a reference to the Express.js app variable.
How do I get the value using process.env.HOST
?
app.set()
doesn't set environment variables, it's just a convenience method offered by Express to be used together with app.get()
.
If you want to set an environment variable in your JS code, use this:
process.env.HOST = 'demo.sample.com';
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