0.42.0 • Published 3 years ago

@zcong/nest-stack-config v0.42.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

config

nestjs 配置模块

Install

$ npm install @zcong/nest-stack-config --save
# or yarn
$ yarn add @zcong/nest-stack-config

Usage

此模块与 eggjs 的配置模块类似

全局配置:

import { Module } from '@nestjs/common';
import { ConfigModule } from '@zcong/nest-stack-config';

interface Config {
  name: string;
  optional?: number;
}

const defaultConfig = (): Config => ({ name: 'default' });
const localConfig = (): Config => ({ name: 'local', optional: 1 });
const testConfig = (): Config => ({ name: 'test', optional: 2 });
const prodConfig = (): Config => ({ name: 'prod', optional: 3 });

@Module({
  imports: [
    ConfigModule.registry({
      default: defaultConfig,
      local: localConfig,
      testConfig: testConfig,
      prod: prodConfig,
    }),
  ],
  controllers: [],
  providers: [],
})
export class AppModule {}

可以注入任何服务使用:

import { ConfigService } from '@zcong/nest-stack-config';

@Injectable()
class TestService {
  constructor(private readonly configService: ConfigService<Config>) {}

  test() {
    // get config
    this.configService.getConfig();
  }
}

不同 NODE_ENV 会获取不同配置, 配置均会和 default 配置使用 extend2 merge:

  1. local 默认环境,会加载 local config merge default config
  2. prod 环境,会加载 prod config merge default config
  3. test 环境,会加载 test config merge default config
0.42.0

3 years ago

0.41.5

3 years ago

0.41.4

3 years ago

0.41.1

3 years ago

0.41.2

3 years ago

0.41.0

3 years ago

0.41.3

3 years ago

0.40.0

3 years ago

0.13.5

4 years ago

0.15.0

4 years ago

0.14.0

4 years ago

0.13.4

4 years ago

0.13.1

4 years ago

0.12.0

4 years ago

0.11.0

4 years ago

0.10.2

4 years ago

0.10.0

4 years ago

0.9.0

4 years ago

0.8.0

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.3

4 years ago

0.5.0

4 years ago