项目作者: aleksandryackovlev

项目描述 :
Etcd3 module for Nest framework (node.js)
高级语言: TypeScript
项目地址: git://github.com/aleksandryackovlev/nestjs-etcd.git
创建时间: 2020-12-28T18:25:55Z
项目社区:https://github.com/aleksandryackovlev/nestjs-etcd

开源协议:MIT License

下载


npm
deps
Build Status
codecov
size

Description

Etcd3 module for Nest.

Installation

  1. $ npm i --save nestjs-etcd

Getting Started

To register the EtcdModule in app.module.ts

  1. import { Module } from '@nestjs/common';
  2. import { EtcdModule} from 'nestjs-etcd';
  3. @Module({
  4. imports: [
  5. EtcdModule.forRoot({
  6. name: 'client_name', // optional, default to 'default'
  7. hosts: `http://0.0.0.0:2379`,
  8. }),
  9. ],
  10. })
  11. export class AppModule {}

With Async

  1. import { Module } from '@nestjs/common';
  2. import { EtcdModule} from 'nestjs-etcd';
  3. @Module({
  4. imports: [
  5. EtcdModule.forRootAsync({
  6. name: 'client_name', // optional, default to 'default'
  7. useFactory: (configService: ConfigService) => ({
  8. hosts: configService.get('hosts'),
  9. }),
  10. inject:[ConfigService],
  11. }),
  12. ],
  13. })
  14. export class AppModule {}

Module supports all the options for Etcd3 package (see https://microsoft.github.io/etcd3/interfaces/ioptions.html):

  1. type EtcdModuleOptions = IOptions & { name?: string }

Usage

  1. import { Injectable } from '@nestjs/common';
  2. import { Etcd3 } from 'etcd3';
  3. import { InjectClient } from 'nestjs-etcd';
  4. @Injectable()
  5. export class TestService {
  6. // client_name is optional for InjectClient, default to 'default'
  7. constructor(@InjectClient('client_name') private readonly client: Etcd3) {}
  8. find(key: string): Promise<string> {
  9. return this.client.get(key).string();
  10. }
  11. }

Contributing

Please take a moment to read our contributing guidelines if you haven’t yet done so.

CONTRIBUTING

License

MIT