🦅 NestJS Beginner

What is the @nestjs/config module?

Answer

The @nestjs/config package provides NestJS-idiomatic configuration management using environment variables and .env files. Register it in AppModule: ConfigModule.forRoot({ isGlobal: true }). Making it global means you do not need to import ConfigModule in every feature module. Inject ConfigService wherever needed: constructor(private config: ConfigService) {}. Read values: this.config.get('DATABASE_URL'). For type-safe configuration, define a validation schema with Joi: ConfigModule.forRoot({ validationSchema: Joi.object({ PORT: Joi.number().default(3000) }) }). The module validates all environment variables at startup, failing fast with clear error messages if required config is missing.