Express - Setting environment

env variable is used to store the current environment node for this particular Node.js process.

The value is automatically set by Express.js from process.env.NODE_ENV, or development if that value is not set.

The most common values for env setting are:

  • test
  • stage
  • preview
  • production

We can argument the env by:

1
2
3
4
app.set('env', 'preview');
// OR
process.env.NODE_ENV = 'preview';

However, the better way is to start the app in the CLI:

1
NODE_ENV=preview node app
0%