{"id":19774361,"url":"https://github.com/vinks/nest-consul-config","last_synced_at":"2026-06-10T08:31:36.046Z","repository":{"id":141672382,"uuid":"167543842","full_name":"vinks/nest-consul-config","owner":"vinks","description":"A Nest framework (node.js) module for getting configurations from consul kv","archived":false,"fork":false,"pushed_at":"2018-12-19T03:33:54.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T11:51:52.357Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vinks.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-01-25T12:26:35.000Z","updated_at":"2020-03-05T04:49:32.000Z","dependencies_parsed_at":null,"dependency_job_id":"8b24a400-ffff-4311-9b13-24cb5dc14847","html_url":"https://github.com/vinks/nest-consul-config","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/vinks/nest-consul-config","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-config","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-config/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-config/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-config/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinks","download_url":"https://codeload.github.com/vinks/nest-consul-config/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-config/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34144679,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-10T02:00:07.152Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-12T05:12:45.392Z","updated_at":"2026-06-10T08:31:31.024Z","avatar_url":"https://github.com/vinks.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\n  \u003ca href=\"http://nestjs.com/\" target=\"blank\"\u003e\u003cimg src=\"https://nestjs.com/img/logo_text.svg\" width=\"320\" alt=\"Nest Logo\" /\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n## Description\n\nA component of [nestcloud](http://github.com/nest-cloud/nestcloud). NestCloud is a nest framework micro-service solution.\n  \n[中文文档](https://nestcloud.org/solutions/pei-zhi-zhong-xin)\n\nThis is a [Nest](https://github.com/nestjs/nest) module to get configurations from consul kv.\n\n## Installation\n\n```bash\n$ npm i --save nest-consul consul nest-consul-config\n```\n\n## Quick Start\n\n#### Import Module\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ConsulModule } from 'nest-consul';\nimport { ConsulConfigModule } from 'nest-consul-config';\n\nconst env = process.env.NODE_ENV;\n\n@Module({\n  imports: [\n      ConsulModule.register({\n        host: '127.0.0.1',\n        port: 8500\n      }),\n      ConsulConfigModule.register({key: `config__user-service__${env}`})\n  ],\n})\nexport class ApplicationModule {}\n```\n\nIf you use [nest-boot](https://github.com/miaowing/nest-boot) module.\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ConsulModule } from 'nest-consul';\nimport { ConsulConfigModule } from 'nest-consul-config';\nimport { BootModule, BOOT_ADAPTER } from 'nest-boot';\n\n@Module({\n  imports: [\n      ConsulModule.register({adapter: BOOT_ADAPTER}),\n      BootModule.register(__dirname, 'bootstrap.yml'),\n      ConsulConfigModule.register({adapter: BOOT_ADAPTER})\n  ],\n})\nexport class ApplicationModule {}\n```\n\n##### Nest-boot config file\n\n```yaml\nweb:\n  serviceId:\n  serviceName: user-service\nconsul:\n  host: localhost\n  port: 8500\n  config:\n    # available expressions: {serviceName} {serviceId} {env}\n    key: config__{serviceName}__{env}\n    retry: 5\n```\n\n#### Config Client Injection\n\nIn consul kv, the key is \"config__user-service__development\".\n\n```yaml\nuser:\n  info:\n    name: 'test'\n```\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectConfig, ConsulConfig } from 'nest-consul-config';\n\n@Injectable()\nexport class TestService {\n  constructor(\n      @InjectConfig() private readonly config: ConsulConfig\n  ) {}\n\n  getUserInfo() {\n      const userInfo = this.config.get('user.info', {name: 'judi'});\n      console.log(userInfo);\n  }\n}\n```\n\nDynamic config update:\n\n```typescript\nimport { Injectable } from '@nestjs/common';\nimport { InjectConfig, ConsulConfig, DynamicConfig, ConfigValue, OnUpdate } from 'nest-consul-config';\n\n@Injectable()\nexport class TestService extends DynamicConfig implements OnUpdate {\n  @ConfigValue('user.info', {name: 'judi'})\n  private readonly userInfo;\n  \n  constructor(\n      @InjectConfig() private readonly config: ConsulConfig\n  ) {\n      super(config);\n  }\n  \n  onUpdate() {\n      // Some service need re-initial after the config updated, you can execute it here.\n  }\n\n  getUserInfo() {\n      return this.userInfo;\n  }\n}\n```\n\n## API\n\n### class ConsulConfigModule\n\n#### static register\\(options\\): DynamicModule\n\nImport nest consul config module.\n\n| field | type | description |\n| :--- | :--- | :--- |\n| options.adapter | string | if you are using nest-boot module, please set BOOT_ADAPTER |\n| options.key | string | the key of consul kv |\n| options.retry | number | the max retry count when get configuration fail |\n\n### class ConsulConfig\n\n#### get\\(path?: string, defaults?: any\\): any\n\nGet configuration from consul kv.\n\n| field | type | description |\n| :--- | :--- | :--- |\n| path | string | the path of the configuration |\n| defaults | any | default value if the specific configuration is not exist |\n\n#### getKey\\(\\): string\n\nGet the current key.\n\n#### onChange\\(callback: \\(configs\\) =\u0026gt; void\\): void\n\nwatch the configurations.\n\n| field | type | description |\n| :--- | :--- | :--- |\n| callback | \\(configs\\) =\u0026gt; void | callback function |\n\n#### async set\\(path: string, value: any\\): void\n\nupdate configuration.\n\n| field | type | description |\n| :--- | :--- | :--- |\n| path | string | the path of the configuration |\n| value | any | the configuration |\n\n## Stay in touch\n\n- Author - [Miaowing](https://github.com/miaowing)\n\n## License\n\n  Nest is [MIT licensed](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinks%2Fnest-consul-config","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinks%2Fnest-consul-config","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinks%2Fnest-consul-config/lists"}