.forRoot(): environment variable key/value pairs are parsed and resolved. registers the ConfigService provider.

ConfigService: several options for accessing. first need to inject ConfigService

Custom configuration files

  1. also manage custom files such as YAML files
  2. Configuration namespaces: return a "namespaced" configuration object with the registerAs() function

Validation: It is standard practice to throw an exception during application startup if required environment variables haven't been provided or if they don't meet certain validation rules.

  1. Joi built-in validator
  2. A custom validate() function

Expandable variables: supports environment variable expansion

Using in the main.ts: it can still be used in the main.ts file

예시

Managing Configs in NestJs.

How to setup different environments in Nest.js

Managing multiple environments in NestJS