I've got a app.config.ts file with plenty of config variables that look like this:
export const exampleConfig = (config: ConfigService) => {
// Do stuff
return config.get('EXAMPLE')
}
And I've got my schema.prisma file which requires a database URL... Currently, I use this config file on my app.module.ts and on my main.ts:
AppModule:
ExampleModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: exampleConfig
}),
Main:
[...]
import { ConfigService } from '@nestjs/config';
import { exampleConfig } from './config/app.config';
[...]
(async function bootstrap() {
const app = await NestFactory.create(AppModule);
const configService = app.get(ConfigService);
[...]
app.exampleCallThatNeedsConfig(exampleConfig(configService));
await app.listen(3000);
})();
Notice how I always use @nestjs/config configService on my app.config.ts? The thing here is, my schema.prisma file needs a DB_URL, but I cannot use configService nor anything quite like that in there... I could use a env('DB_URL') as the docs tells me to do, but I'd like to keep using the same pattern all over my application, so I'd rather stick with configService