Reputation: 6895
I have an Express.js app for which the production environment name is foo
. So I start my app like NODE_ENV=foo node app.js
. In general this is a bad idea.
Now my app knows it is in production, but Express doesn't know. Regardless of whether this is a good idea or not in general, is there a way to tell Express that it's running in production?
Upvotes: 0
Views: 636
Reputation: 5078
I think you're misusing the NODE_ENV
setting. If you would set the value to production
, ie. you're running Node in production enviroment (that you happen to call foo
), Express would read it automatically.
You can use app.set('env', 'production');
to set the mode if you really must use NODE_ENV
for other purposes. Then you would need a way to tell your app if it is in production mode, eg.
if (process.env.NODE_ENV === 'foo') {
app.set('env', 'production');
}
or introduce another environment variable and use its value: app.set('env', process.env.REAL_NODE_ENV);
and then run with NODE_ENV=foo REAL_NODE_ENV=production node app.js
I would still suggest to use another environment variable than NODE_ENV
to tell your app it's running on foo
.
Upvotes: 3