@nestcfork/consul
TypeScript icon, indicating that this package has built-in type declarations

0.7.5 • Public • Published

NestCloud - Consul

NPM Version Package License NPM Downloads Travis Linux Coverage

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.

field type description
options.host string consul host
options.port string consul port
options.secure boolean security or not
options.ca string[] certs
options.defaults any default consul config

static forRootAsync(options: Options): DynamicModule

Import consul module.

field type description
options.inject string[] 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.

field type description
name string consul key
options.type text json yaml value type
options.defaults any default value

Stay in touch

License

NestCloud is MIT licensed.

Readme

Keywords

none

Package Sidebar

Install

npm i @nestcfork/consul

Weekly Downloads

0

Version

0.7.5

License

MIT

Unpacked Size

21.3 kB

Total Files

27

Last publish

Collaborators

  • kurbar