0.7.17 • Published 3 years ago

@nestcloud/config v0.7.17

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

NestCloud - Config

Description

A NestCloud component for getting and watching configurations from consul kv.

中文文档

Installation

$ npm i --save @nestcloud/consul consul @nestcloud/config

Quick Start

Import Module

import { Module } from '@nestjs/common';
import { ConsulModule } from '@nestcloud/consul';
import { ConfigModule } from '@nestcloud/config';
import { BootModule } from '@nestcloud/boot';
import { NEST_BOOT } from '@nestcloud/common';

@Module({
  imports: [
      ConsulModule.register({dependencies: [NEST_BOOT]}),
      BootModule.register(__dirname, 'bootstrap.yml'),
      ConfigModule.register({dependencies: [NEST_BOOT]})
  ],
})
export class ApplicationModule {}

Configurations

consul:
  host: localhost
  port: 8500
  service: 
    id: null
    name: example-service
  config:
    key: config__${{ consul.service.name }}__${{ NODE_ENV }}

How to get remote configurations

In consul kv, the key is "configexample-servicedevelopment".

user:
  info:
    name: 'test'

Inject Config Client

import { Injectable } from '@nestjs/common';
import { InjectConfig, Config } from '@nestcloud/config';

@Injectable()
export class TestService {
  constructor(
      @InjectConfig() private readonly config: Config
  ) {}

  getUserInfo() {
      const userInfo = this.config.get('user.info', {name: 'judi'});
      console.log(userInfo);
  }
}

Inject value

import { Injectable } from '@nestjs/common';
import { ConfigValue } from '@nestcloud/config';

@Injectable()
export class TestService {
  @ConfigValue('user.info', {name: 'judi'})
  private readonly userInfo;

  getUserInfo() {
      return this.userInfo;
  }
}

API

### class ConfigModule

static register(options): DynamicModule

Register consul config module.

fieldtypedescription
options.dependenciesstring[]if you are using @nestcloud/boot module, please set NEST_BOOT
options.retrynumberthe max retry count when get configuration fail

class Config

get(path?: string, defaults?: any): any

Get configuration from consul kv.

fieldtypedescription
pathstringthe path of the configuration
defaultsanydefault value if the specific configuration is not exist

getKey(): string

Get the current key.

watch(path: string, callback: (configs: any) => void): void

Watch the configurations.

fieldtypedescription
callback(configs) => voidcallback function

async set(path: string, value: any): void

Update configuration.

fieldtypedescription
pathstringthe path of the configuration
valueanythe configuration

Decorators

ConfigValue(path?: string, defaultValue?: any): PropertyDecorator

Inject configuration to attribute. It will change realtime when the value changed in consul kv.

Stay in touch

License

NestCloud is MIT licensed.

0.7.3-node1011

3 years ago

0.7.17

4 years ago

0.6.13

4 years ago

0.6.12

4 years ago

0.7.16

4 years ago

0.7.15

4 years ago

0.7.14

4 years ago

0.7.13

4 years ago

0.7.11

4 years ago

0.7.12

4 years ago

0.7.10

4 years ago

0.7.9

4 years ago

0.7.9-2

4 years ago

0.7.9-1

4 years ago

0.7.9-0

4 years ago

0.7.8

4 years ago

0.7.6

4 years ago

0.7.5

4 years ago

0.7.4

4 years ago

0.7.2

4 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.10-22

4 years ago

0.6.10

4 years ago

0.6.11

4 years ago

0.6.10-15

4 years ago

0.6.10-16

4 years ago

0.6.10-17

4 years ago

0.6.10-18

4 years ago

0.6.10-20

4 years ago

0.6.10-21

4 years ago

0.6.10-19

4 years ago

0.6.10-14

4 years ago

0.6.10-12

4 years ago

0.6.10-13

4 years ago

0.6.10-11

4 years ago

0.6.10-10

4 years ago

0.6.10-6

4 years ago

0.6.10-7

4 years ago

0.6.10-8

4 years ago

0.6.10-9

4 years ago

0.6.10-5

4 years ago

0.6.10-4

4 years ago

0.6.10-3

4 years ago

0.6.10-2

4 years ago

0.6.9

4 years ago

0.6.8

4 years ago

0.6.7

4 years ago

0.6.6

4 years ago

0.6.5

4 years ago

0.6.4

4 years ago

0.6.3

4 years ago

0.6.2

4 years ago

0.6.0

4 years ago

0.6.0-y.4

4 years ago

0.6.0-y.3

4 years ago

0.6.0-y.2

4 years ago

0.6.0-y.1

4 years ago

0.6.0-y.0

4 years ago

0.6.0-4

4 years ago

0.6.0-3

4 years ago

0.6.0-2

4 years ago

0.6.0-1

4 years ago

0.6.0-0

4 years ago

0.5.3

4 years ago

0.5.2

5 years ago

0.5.1

5 years ago

0.5.0-9

5 years ago

0.5.0-8

5 years ago

0.5.0-7

5 years ago

0.5.0-6

5 years ago

0.5.0-5

5 years ago

0.5.0-4

5 years ago

0.5.0-3

5 years ago

0.5.0-2

5 years ago

0.5.0-1

5 years ago

0.5.0-0

5 years ago

0.4.5-3

5 years ago

0.4.5-2

5 years ago

0.4.5-1

5 years ago

0.4.5-0

5 years ago