Multi-environment configuration
Overview
DMNO supports multiple environments out of the box. This allows you to define different configuration item values in each environments. For example: development, staging, and production.
Configuration
To define different configurations for different environments, you can use the switchByNodeEnv
helper method. This method takes an object where the keys are the environment names and the values are the configuration item for each environment. As is implied by the name, the configuration item for the current environment is selected based on the value of the NODE_ENV
environment variable.
You can define as many configuration items as you need using the switchByNodeEnv
method.
Environment variables
To set the environment for your application, you can use the NODE_ENV
environment variable. This variable is commonly set to development
, staging
, or production
depending on the environment.
For example, to set the environment to production
and do a production build, you could run:
This is especially useful when the value of NODE_ENV
might not be what you would expect (we’re looking at you Netlify). For example, when running a build on a CI server, you might want to set the environment to production
to ensure that the correct configuration values are used.
Other environments
You may have a different env var that you want to use to switch between values. For example, you might want to use APP_ENV
instead of NODE_ENV
. You can do this by passing the name of the env var you want to use as the first argument to switchBy
.