Files
main.tsmain
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
Press Run tests to start the app. Its log appears here.Graded endpoints
configuration.ts shaped .env into shelter.name and shelter.capacity, read through ConfigService; capacityFromEnv is a number because validate() converted it before ConfigService stored it
SHELTER_MOTTO is not in .env, so ConfigService.get returns the default
The first of three cats the capacity allows
Second of three
Third of three
SHELTER_CAPACITY=3 in .env reached the service as shelter.capacity, and the message carries the shelter's name
Three cats