So I followed the guide on how to create a configuration for my Nest app
https://docs.nestjs.com/techniques/configuration
and due to the fact I have many configuration parts I wanted to split the parts into multiple configuration services. So my app.module.ts imports a custom config module
@Module({
imports: [CustomConfigModule]
})
export class AppModule {}
This custom config module (config.module.ts) bundles all the config services and loads the Nest config module
@Module({
imports: [ConfigModule.forRoot()],
providers: [ServerConfigService],
exports: [ServerConfigService],
})
export class CustomConfigModule {}
Lastly I have a simple config service server.config.service.ts which returns the port the application is running on
@Injectable()
export class ServerConfigService {
constructor(private readonly configService: ConfigService) {}
public get port(): number {
return this.configService.get<number>('SERVER_PORT');
}
}
I would like to validate those services on application startup. The docs explain how to setup a validationschema for the configuration module
https://docs.nestjs.com/techniques/configuration#schema-validation
How can I use that for my service validation when using a custom config module? Do I have to call joi in each service constructor and validate the properties there?
Thanks in advance