使用 dotenv 的 nestjs 配置模块:key:
Nestjs 配置 用于 NestJs 的配置组件。
纱线
yarn add nestjs-configNPM
npm install nestjs-config --save假设我们的项目中有一个名为 src/config 的文件夹,其中包含多个配置文件。
/src
├── app.module.ts
├── config
│ ├── express.ts
│ ├── graphql.ts
│ └── grpc.ts让我们在 app.module.ts 中注册 config 模块
import { Module } from '@nestjs/common';
import { ConfigModule } from 'nestjs-config';
import * as path from 'path';
@Module({
imports: [
ConfigModule.load(path.resolve(__dirname, 'config', '**/!(*.d).{ts,js}')),
],
})
export class AppModule {}现在假设您的应用程序不位于名为 src 的文件夹中,而是位于 src/app 中。
我们希望能够设置不同的'根路径'来加载配置文件。无论是 src 还是 dist。
暂无开放 Issues,或尚未同步最近议题。