0.10.2 • Published 2 years ago

@donews/nestjs-config v0.10.2

Weekly downloads
49
License
MIT
Repository
github
Last release
2 years ago

nest config module

参照官方 @nestjs/config

描述

基于js-yamlNest配置 module。

区别

  1. 删除 dotenv 支持,转向 js-yaml 支持
  2. 官方结构过于复杂
  3. load 功能关闭,此项只能加载配置,直接配置文件就行,场景不明

待支持:

  1. load 增加加载类的可能性,用于扩充 configService
  2. configService 在读取时可能发生错误,因为 key 不存在,发生错误

Install

$ npm i @donews/nestjs-config

Quick Start

假定一个目录结构,其中包含${rootPath}/config

/root
    /config
        development.yaml
    /src
        app.module.ts

1. 模块导入

import { Module } from '@nestjs/common';
import { ConfigModule } from '@donews/nestjs-config';
import { join } from 'path';

@Module({
  import: [
    ConfigModule.forRoot({
      envFilePath: join(process.cwd(), './config/development.yaml'),
    }),
  ],
})
export class AppModule {}

2. ConfigModuleOptions 对应的值

export interface ConfigModuleOptions {
  // 是否将模块全局化
  isGlobal?: boolean;

  // 是否忽略环境变量配置文件
  ignoreEnvFile?: boolean;

  // 是否忽略检测 命令行输入的参数 检测
  ignoreCheckEnvVars?: boolean;

  // 配置文件地址,支持数组
  envFilePath?: string | string[];

  // 编码格式,暂时无效
  encoding?: string;

  // 校验参数 joi包
  validationSchema?: 'Joi.AnySchema';

  // joi 校验参数
  validationOptions?: 'ValidationOptions';
}

3. 使用

import { ConfigService } from '@donews/nestjs-config';

class TestService {
  constructor(private readonly configService: ConfigService) {}

  say() {
    this.configService.get<number>('PORT');
  }
}

License

Nest is MIT licensed.

0.10.2

2 years ago

0.10.0

2 years ago

0.9.3

3 years ago

0.9.2

3 years ago

0.9.0

3 years ago

0.9.1

3 years ago

0.8.4

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.11

4 years ago

0.1.10

4 years ago

0.1.2

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.4

4 years ago

0.1.3

4 years ago

0.1.5

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago