Configuration — Techniques · NestJS

Move the shelter's name and capacity out of the code and into .env: load it with ConfigModule, shape it with a configuration factory, validate it before the app boots, and read it through ConfigService.

What you will learn

Read the theory for Configuration

All Techniques lessons

All NestJS courses

loading types…

What you'll learn

  • Register ConfigModule.forRoot() once, globally, and explain what it reads and in what order of precedence
  • Shape raw environment variables into nested configuration with a factory passed to load, and read it with ConfigService.get('a.b') and a default
  • Validate the environment before the application boots with a validate function built on class-validator and class-transformer