Breaking changes
The order in which configuration variables are read by the ConfigService#get
method has been updated. The new order is:
- Internal configuration (config namespaces and custom config files)
- Validated environment variables (if validation is enabled and a schema is provided)
- The
process.env
object
Previously, validated environment variables and the process.env
object were read first, preventing them from being overridden by internal configuration. With this update, internal configuration will now always take precedence over environment variables.
Additionally, the ignoreEnvVars
configuration option, which previously allowed disabling validation of the process.env
object, has been deprecated. Instead, use the validatePredefined
option (set to false
to disable validation of predefined environment variables). Predefined environment variables refer to process.env
variables that were set before the module was imported. For example, if you start your application with PORT=3000 node main.js
, the PORT
variable is considered predefined. However, variables loaded by the ConfigModule
from a .env
file are not classified as predefined.
A new skipProcessEnv
option has also been introduced. This option allows you to prevent the ConfigService#get
method from accessing the process.env
object entirely, which can be helpful when you want to restrict the service from reading environment variables directly.