Skip to content
This repository has been archived by the owner. It is now read-only.
[Migrated to nestcloud repository]A Consul module for Nest framework (node.js)
TypeScript JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib
.eslintrc.js
.gitignore
.npmignore
.prettierrc
README.md
index.d.ts
index.js
index.ts.js
package.json
tsconfig.json
tslint.json
yarn.lock

README.md

Nest Logo

Description

A component of nestcloud. NestCloud is a nest framework micro-service solution.

中文文档

This is a Consul module for Nest, based on node-consul.

Installation

$ npm i --save @nestcloud/consul consul

Quick Start

Import Module

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

@Module({
  imports: [ConsulModule.register({
    host: '127.0.0.1',
    port: 8500
  })],
})
export class ApplicationModule {}

If you use @nestcloud/boot module.

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

@Module({
  imports: [
      BootModule.register(__dirname, 'bootstrap.yml'),
      ConsulModule.register({dependencies: [NEST_BOOT]})
  ],
})
export class ApplicationModule {}
Nest-boot config file
consul:
  host: localhost
  port: 8500

Usage

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

@Injectable()
export class TestService {
  constructor(@InjectConsul() private readonly consul: Consul) {}
}
Simple Get Consul KV
import { Injectable } from '@nestjs/common';
import { ConsulKV } from '@nestcloud/consul';

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

API

class ConsulModule

static register(options: Options): DynamicModule

Import nest consul module.

field type description
options.dependencies string[] if you are using @nestcloud/boot module, please set [NEST_BOOT]
其他 any see node-consul

class Consul

see node-consul

Decorators

ConsulKV(key: string, type?: 'json' | 'yaml' | 'text', defaults?: any): PropertyDecorator

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

Stay in touch

License

NestCloud is MIT licensed.

You can’t perform that action at this time.