ConfigModuleOptions


interface ConfigModuleOptions<ValidationOptions extends Record<string, any> = Record<string, any>> {
  cache?: boolean
  isGlobal?: boolean
  ignoreEnvFile?: boolean
  ignoreEnvVars?: boolean
  envFilePath?: string | string[]
  validate?: (config: Record<string, any>) => Record<string, any>
  validatePredefined?: boolean
  skipProcessEnv?: boolean
  validationSchema?: any
  validationOptions?: ValidationOptions
  load?: Array<ConfigFactory | Promise<ConfigFactory>>
  expandVariables?: boolean | DotenvExpandOptions
}

Properties

Property Description
cache?: boolean

If "true", values from the process.env object will be cached in the memory. This improves the overall application performance. See: https://github.com/nodejs/node/issues/3104

isGlobal?: boolean

If "true", registers ConfigModule as a global module. See: https://docs.nestjs.com/modules#global-modules

ignoreEnvFile?: boolean

If "true", environment files (.env) will be ignored.

ignoreEnvVars?: boolean

If "true", predefined environment variables will not be validated.

envFilePath?: string | string[]

Path to the environment file(s) to be loaded.

validate?: (config: Record<string, any>) => Record<string, any>

Custom function to validate environment variables. It takes an object containing environment variables as input and outputs validated environment variables. If exception is thrown in the function it would prevent the application from bootstrapping. Also, environment variables can be edited through this function, changes will be reflected in the process.env object.

validatePredefined?: boolean

If "true", predefined environment variables will be validated. Predefined environment variables are process variables (process.env variables) that were set before the module was imported. For example, if you start your application with PORT=3000 node main.js, then PORT is a predefined environment variable. Variables that were loaded by the ConfigModule from the .env file are not considered predefined.

skipProcessEnv?: boolean

If "true", process environment variables (process.env) will be ignored and not picked up by the ConfigService#get method.

validationSchema?: any

Environment variables validation schema (Joi).

validationOptions?: ValidationOptions

Schema validation options. See: https://joi.dev/api/?v=17.3.0#anyvalidatevalue-options

load?: Array<ConfigFactory | Promise<ConfigFactory>>

Array of custom configuration files to be loaded. See: https://docs.nestjs.com/techniques/configuration

expandVariables?: boolean | DotenvExpandOptions

A boolean value indicating the use of expanded variables, or object containing options to pass to dotenv-expand. If .env contains expanded variables, they'll only be parsed if this property is set to true.