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 nest-consul consul
Quick Start
Import Module
import { Module } from '@nestjs/common';
import { ConsulModule } from 'nest-consul';
@Module({
imports: [ConsulModule.register({
host: '127.0.0.1',
port: 8500
})],
})
export class ApplicationModule {}
If you use nest-boot module.
import { Module } from '@nestjs/common';
import { ConsulModule } from 'nest-consul';
import { BootModule } from 'nest-boot';
import { NEST_BOOT } from 'nest-boot';
@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 { Component } from '@nestjs/common';
import * as Consul from 'consul';
import { InjectConsul } from 'nest-consul';
@Component()
export class TestService {
constructor(@InjectConsul() private readonly consul: Consul) {}
}
API
class ConsulModule
static register(options: Options): DynamicModule
Import nest consul module.
field |
type |
description |
options.dependencies |
string[] |
if you are using nest-boot module, please set [NEST_BOOT] |
其他 |
any |
see node-consul |
class Consul
see node-consul
Stay in touch
License
NestCloud is MIT licensed.