When it comes to app configuration, the terms development and production are overloaded, especially in a repo containing client- and server-side application code.
Often, development and production are simply used as friendly names for the general environment in which an app is running. For example, a server app might be deployed to and run on a remote testing environment named the "development" env. Other common environment names in simple deployment schemes are test, staging and local.
Other times, development and production are used to refer to "modes" of app execution, particularly on the client side. For example, they might be used to suggest whether or not an app should be optimized for performance and security or allowed to contain hooks and other helpers for debugging.
These changes aim to make it easier to manage configuration both for different modes of app execution and for different app environments.
OBJECTIVES
Centralize app configuration; minimize coupling of app logic to process.env object. Where practical:
Replace references to process.env properties with refs to central config props
Replace references to custom global variables with refs to central config props
Replace references to hard-coded env-specific values with refs to central config props
Use more explicit config property names and better distinguish between config properties related to "mode" of app execution vs. those that are based on the actual environment
It lets you specify environment-specific variables along with a default config and automatically merges the env-specific (whatever file matches the current NODE_ENV -- e.g. config/development.js) and default configs together.
What I usually do is set up a config module that not only contains hard-coded non-sensitive values but that also wraps sensitive env-based variables (such as those set in process.env).
Then, the entire app only has to look to the config module to get whatever config it needs. No more hardcoded string comparisons or checking for process.env.foo.
BACKGROUND
When it comes to app configuration, the terms development and production are overloaded, especially in a repo containing client- and server-side application code.
Often, development and production are simply used as friendly names for the general environment in which an app is running. For example, a server app might be deployed to and run on a remote testing environment named the "development" env. Other common environment names in simple deployment schemes are test, staging and local.
Other times, development and production are used to refer to "modes" of app execution, particularly on the client side. For example, they might be used to suggest whether or not an app should be optimized for performance and security or allowed to contain hooks and other helpers for debugging.
These changes aim to make it easier to manage configuration both for different modes of app execution and for different app environments.
OBJECTIVES
process.env
object. Where practical:process.env
properties with refs to central config propsSUGGESTED SOLUTIONS
I've found node-config extremely useful.
It lets you specify environment-specific variables along with a default config and automatically merges the env-specific (whatever file matches the current
NODE_ENV
-- e.g.config/development.js
) and default configs together.What I usually do is set up a
config
module that not only contains hard-coded non-sensitive values but that also wraps sensitive env-based variables (such as those set inprocess.env
).Then, the entire app only has to look to the config module to get whatever config it needs. No more hardcoded string comparisons or checking for
process.env.foo
.Recommending for all of our JS apps.