0.7.5 • Published 4 years ago

@nestcfork/consul v0.7.5

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

NestCloud - Consul

Description

A NestCloud component for providing consul api based on node-consul.

Installation

$ npm i --save @nestcfork/consul consul

Quick Start

Import Module

import { Module } from '@nestjs/common';
import { ConsulModule } from '@nestcfork/consul';
import { BOOT } from '@nestcfork/common';

@Module({
  imports: [
    ConsulModule.forRootAsync({ inject: [BOOT] })
  ],
})
export class AppModule {}

Configurations

consul:
  host: localhost
  port: 8500

Usage

import { Injectable } from '@nestjs/common';
import * as Consul from 'consul';
import { InjectConsul } from '@nestcfork/consul';

@Injectable()
export class TestService {
  constructor(
    @InjectConsul() private readonly consul: Consul
  ) {
  }
}

Simple Get Consul KV

import { Injectable } from '@nestjs/common';
import { WatchKV } from '@nestcfork/consul';

@Injectable()
export class TestService {
  @WatchKV('test_key', 'yaml', {})
  private readonly config: any;
}

API

class ConsulModule

static forRoot(options: Options): DynamicModule

Import consul module.

fieldtypedescription
options.hoststringconsul host
options.portstringconsul port
options.securebooleansecurity or not
options.castring[]certs
options.defaultsanydefault consul config

static forRootAsync(options: Options): DynamicModule

Import consul module.

fieldtypedescription
options.injectstring[]BOOT

class Consul

see node-consul

Decorators

KeyValue(name: string, options?: KeyValueOptions): PropertyDecorator

Inject consul kv to the class attribute, it will update immediately when consul kv update.

fieldtypedescription
namestringconsul key
options.typetext json yamlvalue type
options.defaultsanydefault value

Stay in touch

License

NestCloud is MIT licensed.