I have a couple of apps running on Heroku and it would seem NODE_ENV is always set to production
, even though I have it manually set to development
in the environment variables on heroku.
When deploying, I see this in the logs:
-----> Creating runtime environment
NPM_CONFIG_LOGLEVEL=error
NPM_CONFIG_PRODUCTION=false
NODE_ENV=development
NODE_MODULES_CACHE=true
NODE_VERBOSE=false
So it would look like NODE_ENV is being set appropriately, however the app behaves as if it were set to production
.
Is it possible to override NODE_ENV on heroku?
Thanks.
EDIT:
Here's the code I'm using.
let AUTH_URL = 'https://development.com';
if (process.env.NODE_ENV === 'development') {
AUTH_URL = 'https://development.com'
} else if (process.env.NODE_ENV === 'staging') {
AUTH_URL = 'https://staging.com'
} else if (process.env.NODE_ENV === 'production') {
AUTH_URL = 'https://production.com'
}
export {
AUTH_URL
}
AUTH_URL is then used in other scripts as the base URL to make API calls to. I have NODE_ENV environment variable set to development, but the URL being set is always https://production.com
no matter the value of NODE_ENV on heroku. Here's a screenshot of the environment variables set up on heroku
Check package.json
for start
script. If it has something similar to below it might be overwriting it.
package.json
{
...
"scripts": {
...
"start": "cross-env NODE_ENV=production node ./server/index.js"
},
...
}
So convert it to
{
...
"scripts": {
...
"start": "node ./server/index.js"
},
...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.