Lesson

Configure a NestJS API with Environment Variables using ConfigModule and joi

In this lesson, we add configuration to the NestJS API using a .env file, which Nx Workspace supports out of the box.

Duration
2 min
Access
Free
Transcript
Available

In this lesson, we add configuration to the NestJS API using a .env file, which Nx Workspace supports out of the box.

After adding the @nestjs/config and joi dependencies, we define a configuration and validation schema.

These files are loaded into the ConfigModule, that we import in CoreModule and the values in our .env file are now validated using our schema.

We can now import the ConfigService and use it to get properties from our configuration.