I'm using Express for framework.
And I would like to divide my configuration to "development" and "production".
I know that I can use
app.configure('development', function() {}); app.configure('production', function() {});
But I want to know the way actually how I can know what the NODE_ENV value is.
I tried to find in global variables but I could not find.
I really need this to use other Database configuration depends on NODE_ENV
in my database config.js file.
NODE_ENV is an environment variable that stands for node environment in express server. The NODE_ENV environment variable specifies the environment in which an application is running (usually, development or production).
We see that it in fact reads NODE_ENV and defaults to 'development' if it isn't set. This variable is exposed to applications via 'app. get(“env”)' and can be used to apply environment specific configurations as explained above, but it's up to you to use this or not.
You cannot override NODE_ENV manually. This prevents developers from accidentally deploying a slow development build to production.
To retrieve environment variables in Node. JS you can use process. env. VARIABLE_NAME, but don't forget that assigning a property on process.
I have found the answer
process.env.NODE_ENV
Express also exposes this data via app.settings.env
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