{"id":19774356,"url":"https://github.com/vinks/nest-consul-service","last_synced_at":"2025-09-07T16:35:33.116Z","repository":{"id":141672437,"uuid":"167543883","full_name":"vinks/nest-consul-service","owner":"vinks","description":"A Nest framework (node.js) module for registering and getting consul service easily.","archived":false,"fork":false,"pushed_at":"2019-01-29T16:36:34.000Z","size":170,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T11:51:50.673Z","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:51.000Z","updated_at":"2020-03-05T04:50:17.000Z","dependencies_parsed_at":"2024-07-14T16:19:19.749Z","dependency_job_id":null,"html_url":"https://github.com/vinks/nest-consul-service","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/vinks/nest-consul-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vinks","download_url":"https://codeload.github.com/vinks/nest-consul-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vinks%2Fnest-consul-service/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":274064575,"owners_count":25216341,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-07T02:00:09.463Z","response_time":67,"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:43.332Z","updated_at":"2025-09-07T16:35:33.076Z","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/fu-wu-zhu-ce-yu-fa-xian)\n\nThis is a [Nest](https://github.com/nestjs/nest) module provide service registration and service discovery.\n\n## Installation\n\n```bash\n$ npm i --save nest-consul-service nest-consul consul\n```\n\n## Quick Start\n\n#### Import Module\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ConsulModule } from 'nest-consul';\nimport { ConsulServiceModule, Check, PASSING, WARNING, FAILURE } from 'nest-consul-service';\n\n@Module({\n  imports: [\n      ConsulModule.register({\n          host: '127.0.0.1',\n          port: 8500\n      }),\n      ConsulServiceModule.register({\n        serviceId: 'node1',\n            serviceName: 'user-service',\n            port: 3001,\n            consul: {\n                discovery_host: 'localhost',\n                health_check: {\n                    timeout: '1s',\n                    interval: '10s',\n                },\n                max_retry: 5,\n                retry_interval: 3000,\n            }\n      }),\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 { ConsulServiceModule, Check, PASSING, WARNING, FAILURE } from 'nest-consul-service';\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      ConsulServiceModule.register({adapter: BOOT_ADAPTER}),\n  ],\n})\nexport class ApplicationModule {}\n```\n\n#### Nest-boot config file\n\n```yaml\nweb: \n  serviceId: node1\n  serviceName: user-service\n  port: 3001\nconsul:\n  host: localhost\n  port: 8500\n  discovery_host: localhost\n  health_check:\n    timeout: 1s\n    interval: 10s\n  # when register / deregister the service to consul fail, it will retry five times.\n  max_retry: 5\n  retry_interval: 5000\n```\n\n#### Usage\n\n```typescript\nimport { Component } from '@nestjs/common';\nimport { InjectConsulService, ConsulService } from 'nest-consul-service';\n\n@Component()\nexport class TestService {\n  constructor(@InjectConsulService() private readonly service: ConsulService) {}\n\n  getServices() {\n      const services = this.service.getServices('user-service', {passing: true});\n      this.service.onUpdate('user-service', services =\u003e {\n          console.log(services);\n      });\n      console.log(services);\n  }\n}\n```\n\n#### Custom health check policy\n\nThe health check policy is a function, it will return an object that has status(PASSING, WARNING, CRITICAL) and message.\n\n```typescript\nimport { Module } from '@nestjs/common';\nimport { ConsulModule } from 'nest-consul';\nimport { ConsulServiceModule, PASSING } from 'nest-consul-service';\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      ConsulServiceModule.register({\n        adapter: BOOT_ADAPTER, \n        checks: [() =\u003e {\n          return {status: PASSING, message: 'ok'}\n        }]\n      }),\n  ],\n})\nexport class ApplicationModule {}\n```\n\n## API\n\n### class ConsulServiceModule\n\n#### static register\\(options: RegisterOptions\\): DynamicModule\n\nImport nest consul service module.\n\n| field | type | description |\n| :--- | :--- | :--- |\n| options.adapter | string | if you are using nest-boot module, please set BOOT_ADAPTER |\n| options.serviceId | string | the service id |\n| options.serviceName | string | the service name |\n| options.port | number | the service port |\n| options.consul.discoveryHost | string | the discovery ip |\n| options.consul.health\\_check.timeout | number | the health check timeout, default 1s |\n| options.consul.health\\_check.interval | number | the health check interval，default 10s |\n| options.consul.max\\_retry | number | the max retry count when register service fail |\n| options.consul.retry\\_interval | number | the retry interval when register service fail |\n| options.checks | \\(\\(\\)=\u0026gt; Check\\)\\[\\] | custom health check policies |\n\n### class ConsulService\n\n#### getServices\\(serviceName: string, options?: object\\)\n\nGet available services.\n\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-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinks%2Fnest-consul-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinks%2Fnest-consul-service/lists"}