【发布时间】:2022-01-27 11:37:57
【问题描述】:
我有一个 app.config.ts 文件,其中包含许多如下所示的配置变量:
export const exampleConfig = (config: ConfigService) => {
// Do stuff
return config.get('EXAMPLE')
}
我的 schema.prisma 文件需要一个数据库 URL...目前,我在 app.module.ts 和 main.ts 上使用此配置文件:
AppModule:
ExampleModule.forRootAsync({
imports: [ConfigModule],
inject: [ConfigService],
useFactory: exampleConfig
}),
主要:
[...]
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);
})();
注意我总是在我的app.config.ts 上使用@nestjs/config configService 吗?这里的问题是,我的 schema.prisma 文件需要一个 DB_URL,但我不能使用 configService 也不能在那里使用类似的东西......我可以使用 env('DB_URL') 就像文档告诉我的那样,但我'我想在我的应用程序中继续使用相同的模式,所以我宁愿坚持使用 configService
【问题讨论】:
标签: javascript node.js typescript nestjs prisma