{"id":13465034,"url":"https://github.com/silas/node-consul","last_synced_at":"2025-05-14T14:08:16.611Z","repository":{"id":16158701,"uuid":"18904704","full_name":"silas/node-consul","owner":"silas","description":"Consul client","archived":false,"fork":false,"pushed_at":"2024-10-25T14:03:14.000Z","size":494,"stargazers_count":572,"open_issues_count":7,"forks_count":83,"subscribers_count":16,"default_branch":"main","last_synced_at":"2025-04-28T14:57:18.353Z","etag":null,"topics":["consul","javascript","nodejs"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/consul","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/silas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2014-04-18T06:25:44.000Z","updated_at":"2025-04-26T23:16:57.000Z","dependencies_parsed_at":"2024-11-19T09:01:01.208Z","dependency_job_id":"9711d427-e23e-4841-a383-1acf71832b04","html_url":"https://github.com/silas/node-consul","commit_stats":{"total_commits":265,"total_committers":21,"mean_commits":"12.619047619047619","dds":0.07924528301886791,"last_synced_commit":"a49695291e1861a8545c63b061e191778d35a0f0"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fnode-consul","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fnode-consul/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fnode-consul/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/silas%2Fnode-consul/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/silas","download_url":"https://codeload.github.com/silas/node-consul/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159700,"owners_count":22024564,"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","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":["consul","javascript","nodejs"],"created_at":"2024-07-31T14:00:55.583Z","updated_at":"2025-05-14T14:08:16.581Z","avatar_url":"https://github.com/silas.png","language":"JavaScript","readme":"# Consul\n\nThis is a [Consul][consul] client.\n\n- [Documentation](#documentation)\n- [License](#license)\n\n## Documentation\n\nSee the official [HTTP API][consul-docs-api] docs for more information.\n\n- [Consul](#init)\n  - [Common Method Call Options](#common-options)\n\n* [ACL](#acl)\n  - [Legacy](#acl-legacy)\n* [Agent](#agent)\n  - [Check](#agent-check)\n  - [Service](#agent-service)\n* [Catalog](#catalog)\n  - [Connect](#catalog-connect)\n  - [Node](#catalog-node)\n  - [Service](#catalog-service)\n* [Event](#event)\n* [Health](#health)\n* [KV](#kv)\n* [Query](#query)\n* [Session](#session)\n* [Status](#status)\n* [Transaction](#transaction)\n* [Watch](#watch)\n\n\u003ca id=\"init\"\u003e\u003c/a\u003e\n\n### Consul([options])\n\nInitialize a new Consul client.\n\nOptions\n\n- host (String, default: 127.0.0.1): agent address\n- port (Integer, default: 8500): agent HTTP(S) port\n- secure (Boolean, default: false): enable HTTPS\n- defaults (Object, optional): common method call options that will be included with every call (ex: set default `token`), these options can be override on a per call basis\n\nAdvanced options\n\n- agent (http.Agent|https.Agent, optionals): if not set uses the global agent\n- baseUrl, headers, tags, socketPath, and timeout (see [Papi](https://github.com/silas/node-papi/blob/main/README.md#client) for details)\n- tls options: ca, cert, ciphers, clientCertEngine, crl, dhparam, ecdhCurve, honorCipherOrder, key, passphrase, pfx, rejectUnauthorized, secureOptions, secureProtocol, servername, and sessionIdContext (see [Node.js docs](https://nodejs.org/dist/latest/docs/api/tls.html#tls_tls_connect_options_callback) for details)\n\nUsage\n\n```javascript\nimport Consul from \"consul\";\n\nconst consul = new Consul();\n```\n\n\u003ca id=\"common-options\"\u003e\u003c/a\u003e\n\n### Common Method Call Options\n\nThese options can be included with any method call, although only certain endpoints support them. See the [HTTP API][consul-docs-api] for more information.\n\n- dc (String, optional): datacenter (defaults to local for agent)\n- partition (String, optional): partition (defaults to 'default' partition)\n- wan (Boolean, default: false): return WAN members instead of LAN members\n- consistent (Boolean, default: false): require strong consistency\n- stale (Boolean, default: false): use whatever is available, can be arbitrarily stale\n- index (String, optional): used with `ModifyIndex` to block and wait for changes\n- wait (String, optional): limit how long to wait for changes (ex: `5m`), used with index\n- token (String, optional): ACL token\n- near (String, optional): used to sort the node list in ascending order based on the estimated round trip time from that node\n- node-meta (String[], optional): used to specify a desired node metadata key/value pair of the form key:value\n- filter (String, optional): used to [refine a data query](https://www.consul.io/api/features/filtering.html) for some API listing endpoints\n\nThese options work for all methods.\n\n- ctx (EventEmitter, optional): emit `cancel` to abort request\n- timeout (Number|String, optional): number of milliseconds before request is aborted (ex: `1000` or `1s`)\n\n\u003ca id=\"acl\"\u003e\u003c/a\u003e\n\n### consul.acl\n\n- [bootstrap](#acl-bootstrap)\n- [legacy](#acl-legacy)\n- [replication](#acl-replication)\n\n\u003ca id=\"acl-bootstrap\"\u003e\u003c/a\u003e\n\n### consul.acl.bootstrap()\n\nCreates one-time management token if not configured.\n\nUsage\n\n```javascript\nawait consul.acl.bootstrap();\n```\n\nResult\n\n```json\n{\n  \"ID\": \"adf4238a-882b-9ddc-4a9d-5b6758e4159e\"\n}\n```\n\n\u003ca id=\"acl-replication\"\u003e\u003c/a\u003e\n\n### consul.acl.replication([options])\n\nGet the status of the ACL replication process in the datacenter.\n\nUsage\n\n```javascript\nawait consul.acl.replication();\n```\n\nResult\n\n```json\n{\n  \"Enabled\": true,\n  \"Running\": true,\n  \"SourceDatacenter\": \"dc1\",\n  \"ReplicatedIndex\": 1976,\n  \"LastSuccess\": \"2016-08-05T06:28:58Z\",\n  \"LastError\": \"2016-08-05T06:28:28Z\"\n}\n```\n\n\u003ca id=\"acl-legacy\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy\n\n- [create](#acl-legacy-create)\n- [update](#acl-legacy-update)\n- [destroy](#acl-legacy-destroy)\n- [get](#acl-legacy-get)\n- [clone](#acl-legacy-clone)\n- [list](#acl-legacy-list)\n\n\u003ca id=\"acl-legacy-create\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy.create([options])\n\nCreates a new token with policy.\n\nOptions\n\n- name (String, optional): human readable name for the token\n- type (String, enum: client, management; default: client): type of token\n- rules (String, optional): string encoded HCL or JSON\n\nUsage\n\n```javascript\nawait consul.acl.legacy.create();\n```\n\nResult\n\n```json\n{\n  \"ID\": \"b1f4c10e-b61b-e1de-de95-218c9fefdd3e\"\n}\n```\n\n\u003ca id=\"acl-legacy-update\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy.update(options)\n\nUpdate the policy of a token.\n\nOptions\n\n- id (String): token ID\n- name (String, optional): human readable name for the token\n- type (String, enum: client, management; default: client): type of token\n- rules (String, optional): string encoded HCL or JSON\n\nUsage\n\n```javascript\nawait consul.acl.legacy.update({\n  id: \"63e1d82e-f718-eb92-3b7d-61f0c71d45b4\",\n  name: \"test\",\n});\n```\n\n\u003ca id=\"acl-legacy-destroy\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy.destroy(options)\n\nDestroys a given token.\n\nOptions\n\n- id (String): token ID\n\nUsage\n\n```javascript\nawait consul.acl.legacy.destroy(\"b1f4c10e-b61b-e1de-de95-218c9fefdd3e\");\n```\n\n\u003ca id=\"acl-legacy-get\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy.get(options)\n\nQueries the policy of a given token.\n\nOptions\n\n- id (String): token ID\n\nUsage\n\n```javascript\nawait consul.acl.legacy.get(\"63e1d82e-f718-eb92-3b7d-61f0c71d45b4\");\n```\n\nResult\n\n```json\n{\n  \"CreateIndex\": 7,\n  \"ModifyIndex\": 7,\n  \"ID\": \"63e1d82e-f718-eb92-3b7d-61f0c71d45b4\",\n  \"Name\": \"Read only\",\n  \"Type\": \"client\",\n  \"Rules\": \"{\\\"key\\\":{\\\"\\\":{\\\"policy\\\":\\\"read\\\"}}}\"\n}\n```\n\n\u003ca id=\"acl-legacy-clone\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy.clone(options)\n\nCreates a new token by cloning an existing token.\n\nOptions\n\n- id (String): token ID\n\nUsage\n\n```javascript\nawait consul.acl.legacy.clone(\"63e1d82e-f718-eb92-3b7d-61f0c71d45b4\");\n```\n\nResult\n\n```json\n{\n  \"ID\": \"9fb8b20b-2636-adbb-9b99-d879df3305ec\"\n}\n```\n\n\u003ca id=\"acl-legacy-list\"\u003e\u003c/a\u003e\n\n### consul.acl.legacy.list([options])\n\nLists all the active tokens.\n\nUsage\n\n```javascript\nawait consul.acl.legacy.list();\n```\n\nResult\n\n```json\n[\n  {\n    \"CreateIndex\": 2,\n    \"ModifyIndex\": 2,\n    \"ID\": \"anonymous\",\n    \"Name\": \"Anonymous Token\",\n    \"Type\": \"client\",\n    \"Rules\": \"\"\n  }\n  {\n    \"CreateIndex\": 3,\n    \"ModifyIndex\": 3,\n    \"ID\": \"root\",\n    \"Name\": \"Master Token\",\n    \"Type\": \"management\",\n    \"Rules\": \"\"\n  }\n]\n```\n\n\u003ca id=\"agent\"\u003e\u003c/a\u003e\n\n### consul.agent\n\n- [check](#agent-check)\n- [service](#agent-service)\n- [members](#agent-members)\n- [reload](#agent-reload)\n- [self](#agent-self)\n- [maintenance](#agent-maintenance)\n- [join](#agent-join)\n- [forceLeave](#agent-force-leave)\n\n\u003ca id=\"agent-members\"\u003e\u003c/a\u003e\n\n### consul.agent.members([options])\n\nReturns the members as seen by the consul agent.\n\nOptions\n\n- wan (Boolean, default: false): return WAN members instead of LAN members\n\nUsage\n\n```javascript\nawait consul.agent.members();\n```\n\nResult\n\n```json\n[\n  {\n    \"Name\": \"node1\",\n    \"Addr\": \"127.0.0.1\",\n    \"Port\": 8301,\n    \"Tags\": {\n      \"bootstrap\": \"1\",\n      \"build\": \"0.3.0:441d613e\",\n      \"dc\": \"dc1\",\n      \"port\": \"8300\",\n      \"role\": \"consul\",\n      \"vsn\": \"2\",\n      \"vsn_max\": \"2\",\n      \"vsn_min\": \"1\"\n    },\n    \"Status\": 1,\n    \"ProtocolMin\": 1,\n    \"ProtocolMax\": 2,\n    \"ProtocolCur\": 2,\n    \"DelegateMin\": 2,\n    \"DelegateMax\": 4,\n    \"DelegateCur\": 4\n  }\n]\n```\n\n\u003ca id=\"agent-reload\"\u003e\u003c/a\u003e\n\n### consul.agent.reload([options])\n\nReload agent configuration.\n\nUsage\n\n```javascript\nawait consul.agent.reload();\n```\n\n\u003ca id=\"agent-self\"\u003e\u003c/a\u003e\n\n### consul.agent.self()\n\nReturns the agent node configuration.\n\nUsage\n\n```javascript\nawait consul.agent.self();\n```\n\nResult\n\n```json\n{\n  \"Config\": {\n    \"Bootstrap\": true,\n    \"Server\": true,\n    \"Datacenter\": \"dc1\",\n    \"DataDir\": \"/tmp/node1/data\",\n    \"DNSRecursor\": \"\",\n    \"DNSConfig\": {\n      \"NodeTTL\": 0,\n      \"ServiceTTL\": null,\n      \"AllowStale\": false,\n      \"MaxStale\": 5000000000\n    },\n    \"Domain\": \"consul.\",\n    \"LogLevel\": \"INFO\",\n    \"NodeName\": \"node1\",\n    \"ClientAddr\": \"127.0.0.1\",\n    \"BindAddr\": \"127.0.0.1\",\n    \"AdvertiseAddr\": \"127.0.0.1\",\n    \"Ports\": {\n      \"DNS\": 8600,\n      \"HTTP\": 8500,\n      \"RPC\": 8400,\n      \"SerfLan\": 8301,\n      \"SerfWan\": 8302,\n      \"Server\": 8300\n    },\n    \"LeaveOnTerm\": false,\n    \"SkipLeaveOnInt\": false,\n    \"StatsiteAddr\": \"\",\n    \"Protocol\": 2,\n    \"EnableDebug\": false,\n    \"VerifyIncoming\": false,\n    \"VerifyOutgoing\": false,\n    \"CAFile\": \"\",\n    \"CertFile\": \"\",\n    \"KeyFile\": \"\",\n    \"ServerName\": \"\",\n    \"StartJoin\": [],\n    \"UiDir\": \"\",\n    \"PidFile\": \"/tmp/node1/pid\",\n    \"EnableSyslog\": false,\n    \"SyslogFacility\": \"LOCAL0\",\n    \"RejoinAfterLeave\": false,\n    \"CheckUpdateInterval\": 300000000000,\n    \"Revision\": \"441d613e1bd96254c78c46ee7c1b35c161fc7295+CHANGES\",\n    \"Version\": \"0.3.0\",\n    \"VersionPrerelease\": \"\"\n  },\n  \"Member\": {\n    \"Name\": \"node1\",\n    \"Addr\": \"127.0.0.1\",\n    \"Port\": 8301,\n    \"Tags\": {\n      \"bootstrap\": \"1\",\n      \"build\": \"0.3.0:441d613e\",\n      \"dc\": \"dc1\",\n      \"port\": \"8300\",\n      \"role\": \"consul\",\n      \"vsn\": \"2\",\n      \"vsn_max\": \"2\",\n      \"vsn_min\": \"1\"\n    },\n    \"Status\": 1,\n    \"ProtocolMin\": 1,\n    \"ProtocolMax\": 2,\n    \"ProtocolCur\": 2,\n    \"DelegateMin\": 2,\n    \"DelegateMax\": 4,\n    \"DelegateCur\": 4\n  }\n}\n```\n\n\u003ca id=\"agent-maintenance\"\u003e\u003c/a\u003e\n\n### consul.agent.maintenance(options)\n\nSet node maintenance mode.\n\nOptions\n\n- enable (Boolean): maintenance mode enabled\n- reason (String, optional): human readable reason for maintenance\n\nUsage\n\n```javascript\nawait consul.agent.maintenance(true);\n```\n\n\u003ca id=\"agent-join\"\u003e\u003c/a\u003e\n\n### consul.agent.join(options)\n\nTrigger agent to join a node.\n\nOptions\n\n- address (String): node IP address to join\n- wan (Boolean, default false): attempt to join using the WAN pool\n\nUsage\n\n```javascript\nawait consul.agent.join(\"127.0.0.2\");\n```\n\n\u003ca id=\"agent-force-leave\"\u003e\u003c/a\u003e\n\n### consul.agent.forceLeave(options)\n\nForce remove node.\n\nOptions\n\n- node (String): node name to remove\n\nUsage\n\n```javascript\nawait consul.agent.forceLeave(\"node2\");\n```\n\n\u003ca id=\"agent-check\"\u003e\u003c/a\u003e\n\n### consul.agent.check\n\n- [list](#agent-check-list)\n- [register](#agent-check-register)\n- [deregister](#agent-check-deregister)\n- [pass](#agent-check-pass)\n- [warn](#agent-check-warn)\n- [fail](#agent-check-fail)\n\n\u003ca id=\"agent-check-list\"\u003e\u003c/a\u003e\n\n### consul.agent.check.list()\n\nReturns the checks the agent is managing.\n\nUsage\n\n```javascript\nawait consul.agent.check.list();\n```\n\nResult\n\n```json\n{\n  \"example\": {\n    \"Node\": \"node1\",\n    \"CheckID\": \"example\",\n    \"Name\": \"example\",\n    \"Status\": \"passing\",\n    \"Notes\": \"This is an example check.\",\n    \"Output\": \"\",\n    \"ServiceID\": \"\",\n    \"ServiceName\": \"\"\n  }\n}\n```\n\n\u003ca id=\"agent-check-register\"\u003e\u003c/a\u003e\n\n### consul.agent.check.register(options)\n\nRegisters a new check.\n\nOptions\n\n- name (String): check name\n- id (String, optional): check ID\n- serviceid (String, optional): service ID, associate check with existing service\n- http (String): url to test, 2xx passes, 429 warns, and all others fail\n- tlsskipverify (Boolean, default: false): skip HTTPS verification\n- tcp (String): host:port to test, passes if connection is established, fails otherwise\n- args (String[]): path to check script, requires interval\n- script (String): path to check script, requires interval (DEPRECATED)\n- dockercontainerid (String, optional): Docker container ID to run script\n- grpc (String, optional): gRPC endpoint (ex: `127.0.0.1:12345`)\n- grpcusetls (Boolean, optional): enable TLS for gRPC check\n- shell (String, optional): shell in which to run script (currently only supported with Docker)\n- interval (String): interval to run check, requires script (ex: `15s`)\n- timeout (String, optional): timeout for the check (ex: `10s`)\n- ttl (String): time to live before check must be updated (ex: `60s`)\n- aliasnode (String): ID of a node for an alias check (ex: `web1`)\n- aliasservice (String): ID of a service for an alias check (ex: `web`)\n- notes (String, optional): human readable description of check\n- status (String, optional): initial service status\n- deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after\n  which to automatically deregister service if check remains in critical state\n- successbeforepassing (Number, optional): number of consecutive successful\n  results required before check status transitions to passing\n- failuresbeforecritical (Number, optional): number of consecutive unsuccessful\n  results required before check status transitions to critical\n\nUsage\n\n```javascript\nawait consul.agent.check.register({\n  name: \"example\",\n  ttl: \"15s\",\n  notes: \"This is an example check.\",\n});\n```\n\n\u003ca id=\"agent-check-deregister\"\u003e\u003c/a\u003e\n\n### consul.agent.check.deregister(options)\n\nDeregister a check.\n\nOptions\n\n- id (String): check ID\n\nUsage\n\n```javascript\nawait consul.agent.check.deregister(\"example\");\n```\n\n\u003ca id=\"agent-check-pass\"\u003e\u003c/a\u003e\n\n### consul.agent.check.pass(options)\n\nMark a test as passing.\n\nOptions\n\n- id (String): check ID\n- note (String, optional): human readable message\n\nUsage\n\n```javascript\nawait consul.agent.check.pass(\"example\");\n```\n\n\u003ca id=\"agent-check-warn\"\u003e\u003c/a\u003e\n\n### consul.agent.check.warn(options)\n\nMark a test as warning.\n\nOptions\n\n- id (String): check ID\n- note (String, optional): human readable message\n\nUsage\n\n```javascript\nawait consul.agent.check.warn(\"example\");\n```\n\n\u003ca id=\"agent-check-fail\"\u003e\u003c/a\u003e\n\n### consul.agent.check.fail(options)\n\nMark a test as critical.\n\nOptions\n\n- id (String): check ID\n- note (String, optional): human readable message\n\nUsage\n\n```javascript\nawait consul.agent.check.fail(\"example\");\n```\n\n\u003ca id=\"agent-service\"\u003e\u003c/a\u003e\n\n### consul.agent.service\n\n- [list](#agent-service-list)\n- [register](#agent-service-register)\n- [deregister](#agent-service-deregister)\n- [maintenance](#agent-service-maintenance)\n\n\u003ca id=\"agent-service-list\"\u003e\u003c/a\u003e\n\n### consul.agent.service.list()\n\nReturns the services the agent is managing.\n\nUsage\n\n```javascript\nawait consul.agent.service.list();\n```\n\nResult\n\n```json\n{\n  \"example\": {\n    \"ID\": \"example\",\n    \"Service\": \"example\",\n    \"Tags\": [\"dev\", \"web\"],\n    \"Port\": 80\n  }\n}\n```\n\n\u003ca id=\"agent-service-register\"\u003e\u003c/a\u003e\n\n### consul.agent.service.register(options)\n\nRegisters a new service.\n\nOptions\n\n- name (String): service name\n- id (String, optional): service ID\n- tags (String[], optional): service tags\n- address (String, optional): service IP address\n- port (Integer, optional): service port\n- meta (Object, optional): metadata linked to the service instance\n- check (Object, optional): service check\n  - http (String): URL endpoint, requires interval\n  - tcp (String): host:port to test, passes if connection is established, fails otherwise\n  - script (String): path to check script, requires interval\n  - dockercontainerid (String, optional): Docker container ID to run script\n  - shell (String, optional): shell in which to run script (currently only supported with Docker)\n  - interval (String): interval to run check, requires script (ex: `15s`)\n  - timeout (String, optional): timeout for the check (ex: `10s`)\n  - ttl (String): time to live before check must be updated, instead of http/tcp/script and interval (ex: `60s`)\n  - notes (String, optional): human readable description of check\n  - status (String, optional): initial service status\n  - deregistercriticalserviceafter (String, optional, Consul 0.7+): timeout after\n    which to automatically deregister service if check remains in critical state\n- checks (Object[], optional): service checks (see `check` above)\n- connect (Object, optional): specifies the [configuration](https://www.consul.io/api/agent/service.html#connect-structure) for Connect\n- proxy (Object, optional): specifies the [configuration](https://www.consul.io/docs/connect/registration/service-registration.html) for a Connect proxy instance\n- taggedAddresses (Object, optional): specifies a map of explicit LAN and WAN addresses for the service instance\n\nUsage\n\n```javascript\nawait consul.agent.service.register(\"example\");\n```\n\n\u003ca id=\"agent-service-deregister\"\u003e\u003c/a\u003e\n\n### consul.agent.service.deregister(options)\n\nDeregister a service.\n\nOptions\n\n- id (String): service ID\n\nUsage\n\n```javascript\nawait consul.agent.service.deregister(\"example\");\n```\n\n\u003ca id=\"agent-service-maintenance\"\u003e\u003c/a\u003e\n\n### consul.agent.service.maintenance(options)\n\nSet service maintenance mode.\n\nOptions\n\n- id (String): service ID\n- enable (Boolean): maintenance mode enabled\n- reason (String, optional): human readable reason for maintenance\n\nUsage\n\n```javascript\nawait consul.agent.service.maintenance({ id: \"example\", enable: true });\n```\n\n\u003ca id=\"catalog\"\u003e\u003c/a\u003e\n\n### consul.catalog\n\n- [register](#catalog-register)\n- [deregister](#catalog-deregister)\n- [datacenters](#catalog-datacenters)\n- [connect](#catalog-connect)\n- [node](#catalog-node)\n- [service](#catalog-service)\n\n\u003ca id=\"catalog-register\"\u003e\u003c/a\u003e\n\n### consul.catalog.register(options)\n\nRegisters or updates entries in the catalog.\n\nNOTE: this endpoint is a low-level mechanism for registering or updating entries in the catalog. It is usually preferable to instead use the agent endpoints for registration as they are simpler and perform anti-entropy. It is suggested to read the [catalog API](https://developer.hashicorp.com/consul/api-docs/catalog) documentation before using that.\n\nOptions\n\n- id (String, optional): an optional UUID to assign to the node. This must be a 36-character UUID-formatted string\n- node (String, required): specifies the node ID to register\n- address (String, required): specifies the address to register.\n- taggedaddresses (Object, optional): specifies the tagged addresses\n- nodemeta (Object, optional): specifies arbitrary KV metadata pairs for filtering purposes\n- service (Objet, optional): specifies to register a service\n  - id (String): service ID. If ID is not provided, it will be defaulted to the value of the Service.Service property.\n    Only one service with a given ID may be present per node.\n  - service (String): service name\n  - tags (String[], optional): service tags\n  - meta (Object, optional): metadata linked to the service instance\n  - address (String): service IP address\n  - port (Integer): service port\n- check (Object, optional): specifies to register a check.The register API manipulates the health check entry in the Catalog, but it does not setup the\n  TCP/HTTP check to monitor the node's health.\n  - node (String): the node id this check will bind to\n  - name (String): check name\n  - checkid (String): the CheckID can be omitted and will default to the value of Name. The CheckID must be unique on this node.\n  - serviceid (String): if a ServiceID is provided that matches the ID of a service on that node, the check is treated as a service level health check, instead of a node level health check.\n  - notes (String): notes is an opaque field that is meant to hold human-readable text\n  - status (String): initial status. The Status must be one of `passing`, `warning`, or `critical`.\n  - definition (Object): health check definition\n    - http (String): URL endpoint, requires interval\n    - tlsskipverify (Boolean, default: false): skip HTTPS verification\n    - tlsservername (String): SNI\n    - tcp (String): host:port to test, passes if connection is established, fails otherwise\n    - intervalduration (String): interval to run check, requires script (ex: `15s`)\n    - timeoutduration (String): timeout for the check (ex: `10s`)\n    - deregistercriticalserviceafterduration (String): timeout after\n      which to automatically deregister service if check remains in critical state (ex: `120s`)\n- checks (Object[], optional): multiple checks can be provided by replacing `check` with `checks` and sending an array of `check` objects.\n- skipnodeupdate (Bool, optional): pecifies whether to skip updating the node's information in the registration. Note, if the parameter is enabled for a node that doesn't exist, it will still be created\n\nUsage\n\n```javascript\nawait consul.catalog.register(\"example\");\n```\n\n\u003ca id=\"catalog-deregister\"\u003e\u003c/a\u003e\n\n### consul.catalog.deregister(options)\n\nDeregister entries in the catalog.\n\nNOTE:This endpoint is a low-level mechanism for directly removing entries from the Catalog. It is usually preferable to instead use the agent endpoints for deregistration as they are simpler and perform anti-entropy. It is suggested to read the [catalog API](https://developer.hashicorp.com/consul/api-docs/catalog) documentation before using that.\n\nOptions\n\n- node (String, required): specifies the ID of the node. If no other values are provided, this node, all its services, and all its checks are removed.\n- checkid (String, optional): specifies the ID of the check to remove.\n- serviceid (String, optional): specifies the ID of the service to remove. The service and all associated checks will be removed.\n\nUsage\n\n```javascript\nawait consul.catalog.deregister(\"example\");\n```\n\nor\n\n```javascript\nawait consul.catalog.deregister({ id: \"example\" });\n```\n\n\u003ca id=\"catalog-datacenters\"\u003e\u003c/a\u003e\n\n### consul.catalog.datacenters()\n\nLists known datacenters.\n\nUsage\n\n```javascript\nawait consul.catalog.datacenters();\n```\n\nResult\n\n```json\n[\"dc1\"]\n```\n\n\u003ca id=\"catalog-connect\"\u003e\u003c/a\u003e\n\n### consul.catalog.connect\n\n- [nodes](#catalog-connect-nodes)\n\n\u003ca id=\"catalog-connect-nodes\"\u003e\u003c/a\u003e\n\n### consul.catalog.connect.nodes(options)\n\nLists the nodes for a given Connect-capable service.\n\nOptions\n\n- service (String): service name\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.catalog.connect.nodes(\"example\");\n```\n\nResult\n\n```json\n[\n  {\n    \"ID\": \"40e4a748-2192-161a-0510-9bf59fe950b5\",\n    \"Node\": \"foobar\",\n    \"Address\": \"192.168.10.10\",\n    \"Datacenter\": \"dc1\",\n    \"TaggedAddresses\": {\n      \"lan\": \"192.168.10.10\",\n      \"wan\": \"10.0.10.10\"\n    },\n    \"NodeMeta\": {\n      \"somekey\": \"somevalue\"\n    },\n    \"CreateIndex\": 51,\n    \"ModifyIndex\": 51,\n    \"ServiceAddress\": \"172.17.0.3\",\n    \"ServiceEnableTagOverride\": false,\n    \"ServiceID\": \"32a2a47f7992:nodea:5000\",\n    \"ServiceName\": \"foobar\",\n    \"ServiceKind\": \"connect-proxy\",\n    \"ServiceProxyDestination\": \"my-service\",\n    \"ServicePort\": 5000,\n    \"ServiceMeta\": {\n      \"foobar_meta_value\": \"baz\"\n    },\n    \"ServiceTags\": [\"tacos\"]\n  }\n]\n```\n\n\u003ca id=\"catalog-node\"\u003e\u003c/a\u003e\n\n### consul.catalog.node\n\n- [list](#catalog-node-list)\n- [services](#catalog-node-services)\n\n\u003ca id=\"catalog-node-list\"\u003e\u003c/a\u003e\n\n### consul.catalog.node.list([options])\n\nLists nodes in a given datacenter.\n\nOptions\n\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.catalog.node.list();\n```\n\nResult\n\n```json\n[\n  {\n    \"Node\": \"node1\",\n    \"Address\": \"127.0.0.1\"\n  }\n]\n```\n\n\u003ca id=\"catalog-node-services\"\u003e\u003c/a\u003e\n\n### consul.catalog.node.services(options)\n\nLists the services provided by a node.\n\nOptions\n\n- node (String): node ID\n\nUsage\n\n```javascript\nawait consul.catalog.node.services(\"node1\");\n```\n\nResult\n\n```json\n{\n  \"Node\": {\n    \"Node\": \"node1\",\n    \"Address\": \"127.0.0.1\"\n  },\n  \"Services\": {\n    \"consul\": {\n      \"ID\": \"consul\",\n      \"Service\": \"consul\",\n      \"Tags\": [],\n      \"Port\": 8300\n    },\n    \"example\": {\n      \"ID\": \"example\",\n      \"Service\": \"example\",\n      \"Tags\": [\"dev\", \"web\"],\n      \"Port\": 80\n    }\n  }\n}\n```\n\n\u003ca id=\"catalog-service\"\u003e\u003c/a\u003e\n\n### consul.catalog.service\n\n- [list](#catalog-service-list)\n- [nodes](#catalog-service-nodes)\n\n\u003ca id=\"catalog-service-list\"\u003e\u003c/a\u003e\n\n### consul.catalog.service.list([options])\n\nLists services in a given datacenter.\n\nOptions\n\n- dc (String): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.catalog.service.list();\n```\n\nResult\n\n```json\n{\n  \"consul\": [],\n  \"example\": [\"dev\", \"web\"]\n}\n```\n\n\u003ca id=\"catalog-service-nodes\"\u003e\u003c/a\u003e\n\n### consul.catalog.service.nodes(options)\n\nLists the nodes for a given service.\n\nOptions\n\n- service (String): service name\n- dc (String, optional): datacenter (defaults to local for agent)\n- tag (String, optional): filter by tag\n\nUsage\n\n```javascript\nawait consul.catalog.service.nodes(\"example\");\n```\n\nResult\n\n```json\n[\n  {\n    \"Node\": \"node1\",\n    \"Address\": \"127.0.0.1\",\n    \"ServiceID\": \"example\",\n    \"ServiceName\": \"example\",\n    \"ServiceTags\": [\"dev\", \"web\"],\n    \"ServicePort\": 80\n  }\n]\n```\n\n\u003ca id=\"event\"\u003e\u003c/a\u003e\n\n### consul.event\n\n- [fire](#event-fire)\n- [list](#event-list)\n\n\u003ca id=\"event-fire\"\u003e\u003c/a\u003e\n\n### consul.event.fire(options)\n\nFires a new user event.\n\nOptions\n\n- name (String): event name\n- payload (String|Buffer): payload\n- node (String, optional): regular expression to filter by node\n- service (String, optional): regular expression to filter by service\n- tag (String, optional): regular expression to filter by tag\n\nUsage\n\n```javascript\nawait consul.event.fire(\"deploy\", \"53\");\n```\n\nResult\n\n```json\n{\n  \"ID\": \"4730953b-3135-7ff2-47a7-9d9fc9c4e5a2\",\n  \"Name\": \"deploy\",\n  \"Payload\": \"53\",\n  \"NodeFilter\": \"\",\n  \"ServiceFilter\": \"\",\n  \"TagFilter\": \"\",\n  \"Version\": 1,\n  \"LTime\": 0\n}\n```\n\n\u003ca id=\"event-list\"\u003e\u003c/a\u003e\n\n### consul.event.list([options])\n\nLists the most recent events an agent has seen.\n\nOptions\n\n- name (String, optional): filter by event name\n\nUsage\n\n```javascript\nawait consul.event.list(\"deploy\");\n```\n\nResult\n\n```json\n[\n  {\n    \"ID\": \"4730953b-3135-7ff2-47a7-9d9fc9c4e5a2\",\n    \"Name\": \"deploy\",\n    \"Payload\": \"53\",\n    \"NodeFilter\": \"\",\n    \"ServiceFilter\": \"\",\n    \"TagFilter\": \"\",\n    \"Version\": 1,\n    \"LTime\": 2\n  }\n]\n```\n\n\u003ca id=\"health\"\u003e\u003c/a\u003e\n\n### consul.health\n\n- [node](#health-node)\n- [checks](#health-checks)\n- [service](#health-service)\n- [state](#health-state)\n\n\u003ca id=\"health-node\"\u003e\u003c/a\u003e\n\n### consul.health.node(options)\n\nReturns the health info of a node.\n\nOptions\n\n- node (String): node\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.health.node(\"node1\");\n```\n\nResult\n\n```json\n[\n  {\n    \"Node\": \"node1\",\n    \"CheckID\": \"serfHealth\",\n    \"Name\": \"Serf Health Status\",\n    \"Status\": \"passing\",\n    \"Notes\": \"\",\n    \"Output\": \"Agent alive and reachable\",\n    \"ServiceID\": \"\",\n    \"ServiceName\": \"\"\n  },\n  {\n    \"Node\": \"node1\",\n    \"CheckID\": \"service:example\",\n    \"Name\": \"Service 'example' check\",\n    \"Status\": \"critical\",\n    \"Notes\": \"\",\n    \"Output\": \"\",\n    \"ServiceID\": \"example\",\n    \"ServiceName\": \"example\"\n  }\n]\n```\n\n\u003ca id=\"health-checks\"\u003e\u003c/a\u003e\n\n### consul.health.checks(options)\n\nReturns the checks of a service.\n\nOptions\n\n- service (String): service name\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.health.checks(\"example\");\n```\n\nResult\n\n```json\n[\n  {\n    \"Node\": \"node1\",\n    \"CheckID\": \"service:example\",\n    \"Name\": \"Service 'example' check\",\n    \"Status\": \"critical\",\n    \"Notes\": \"\",\n    \"Output\": \"\",\n    \"ServiceID\": \"example\",\n    \"ServiceName\": \"example\"\n  }\n]\n```\n\n\u003ca id=\"health-service\"\u003e\u003c/a\u003e\n\n### consul.health.service(options)\n\nReturns the nodes and health info of a service.\n\nOptions\n\n- service (String): service name\n- dc (String, optional): datacenter (defaults to local for agent)\n- tag (String, optional): filter by tag\n- passing (Boolean, optional): restrict to passing checks\n\nUsage\n\n```javascript\nawait consul.health.service(\"example\");\n```\n\nResult\n\n```json\n[\n  {\n    \"Node\": {\n      \"Node\": \"node1\",\n      \"Address\": \"127.0.0.1\"\n    },\n    \"Service\": {\n      \"ID\": \"example\",\n      \"Service\": \"example\",\n      \"Tags\": [],\n      \"Port\": 0\n    },\n    \"Checks\": [\n      {\n        \"Node\": \"node1\",\n        \"CheckID\": \"service:example\",\n        \"Name\": \"Service 'example' check\",\n        \"Status\": \"critical\",\n        \"Notes\": \"\",\n        \"Output\": \"\",\n        \"ServiceID\": \"example\",\n        \"ServiceName\": \"example\"\n      },\n      {\n        \"Node\": \"node1\",\n        \"CheckID\": \"serfHealth\",\n        \"Name\": \"Serf Health Status\",\n        \"Status\": \"passing\",\n        \"Notes\": \"\",\n        \"Output\": \"Agent alive and reachable\",\n        \"ServiceID\": \"\",\n        \"ServiceName\": \"\"\n      }\n    ]\n  }\n]\n```\n\n\u003ca id=\"health-state\"\u003e\u003c/a\u003e\n\n### consul.health.state(options)\n\nReturns the checks in a given state.\n\nOptions\n\n- state (String, enum: any, passing, warning, critical): state\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.health.state(\"critical\");\n```\n\nResult\n\n```json\n[\n  {\n    \"Node\": \"node1\",\n    \"CheckID\": \"service:example\",\n    \"Name\": \"Service 'example' check\",\n    \"Status\": \"critical\",\n    \"Notes\": \"\",\n    \"Output\": \"\",\n    \"ServiceID\": \"example\",\n    \"ServiceName\": \"example\"\n  }\n]\n```\n\n\u003ca id=\"kv\"\u003e\u003c/a\u003e\n\n### consul.kv\n\n- [get](#kv-get)\n- [keys](#kv-keys)\n- [set](#kv-set)\n- [del](#kv-del)\n\n\u003ca id=\"kv-get\"\u003e\u003c/a\u003e\n\n### consul.kv.get(options)\n\nReturn key/value (kv) pair(s) or `undefined` if key not found.\n\nOptions\n\n- key (String): path to value\n- dc (String, optional): datacenter (defaults to local for agent)\n- recurse (Boolean, default: false): return all keys with given key prefix\n- index (String, optional): used with `ModifyIndex` to block and wait for changes\n- wait (String, optional): limit how long to wait for changes (ex: `5m`), used with index\n- raw (Boolean, optional): return raw value (can't be used with recursive, implies buffer)\n- buffer (Boolean, default: false): decode value into Buffer instead of String\n\nUsage\n\n```javascript\nawait consul.kv.get(\"hello\");\n```\n\nResult\n\n```json\n{\n  \"CreateIndex\": 6,\n  \"ModifyIndex\": 6,\n  \"LockIndex\": 0,\n  \"Key\": \"hello\",\n  \"Flags\": 0,\n  \"Value\": \"world\"\n}\n```\n\n\u003ca id=\"kv-keys\"\u003e\u003c/a\u003e\n\n### consul.kv.keys(options)\n\nReturn keys for a given prefix.\n\nOptions\n\n- key (String): path prefix\n- dc (String, optional): datacenter (defaults to local for agent)\n- separator (String, optional): list keys up to a given separator\n\nUsage\n\n```javascript\nawait consul.kv.keys(\"a/\");\n```\n\nResult\n\n```json\n[\"a/b\", \"a/c\"]\n```\n\n\u003ca id=\"kv-set\"\u003e\u003c/a\u003e\n\n### consul.kv.set(options)\n\nSet key/value (kv) pair.\n\nOptions\n\n- key (String): key\n- value (String|Buffer): value\n- dc (String, optional): datacenter (defaults to local for agent)\n- flags (Number, optional): unsigned integer opaque to user, can be used by application\n- cas (String, optional): use with `ModifyIndex` to do a check-and-set operation\n- acquire (String, optional): session ID, lock acquisition operation\n- release (String, optional): session ID, lock release operation\n\nUsage\n\n```javascript\nawait consul.kv.set(\"hello\", \"world\");\n```\n\nResult\n\n```json\ntrue\n```\n\n\u003ca id=\"kv-del\"\u003e\u003c/a\u003e\n\n### consul.kv.del(options)\n\nDelete key/value (kv) pair(s).\n\nOptions\n\n- key (String): key\n- dc (String, optional): datacenter (defaults to local for agent)\n- recurse (Boolean, default: false): delete all keys with given key prefix\n- cas (String, optional): use with `ModifyIndex` to do a check-and-set operation (must be greater than `0`)\n\nUsage\n\n```javascript\nawait consul.kv.del(\"hello\");\n```\n\n\u003ca id=\"query\"\u003e\u003c/a\u003e\n\n### consul.query\n\n- [list](#query-list)\n- [create](#query-create)\n- [update](#query-update)\n- [get](#query-get)\n- [destroy](#query-destroy)\n- [execute](#query-execute)\n- [explain](#query-explain)\n\n\u003ca id=\"query-list\"\u003e\u003c/a\u003e\n\n### consul.query.list()\n\nList prepared query.\n\nUsage\n\n```javascript\nawait consul.query.list();\n```\n\nResult\n\n```json\n[\n  {\n    \"ID\": \"422b14b9-874b-4520-bd2e-e149a42b0066\",\n    \"Name\": \"redis\",\n    \"Session\": \"\",\n    \"Token\": \"\",\n    \"Template\": {\n      \"Type\": \"\",\n      \"Regexp\": \"\"\n    },\n    \"Service\": {\n      \"Service\": \"redis\",\n      \"Failover\": {\n        \"NearestN\": 3,\n        \"Datacenters\": [\"dc1\", \"dc2\"]\n      },\n      \"OnlyPassing\": false,\n      \"Tags\": [\"master\", \"!experimental\"]\n    },\n    \"DNS\": {\n      \"TTL\": \"10s\"\n    },\n    \"RaftIndex\": {\n      \"CreateIndex\": 23,\n      \"ModifyIndex\": 42\n    }\n  }\n]\n```\n\n\u003ca id=\"query-create\"\u003e\u003c/a\u003e\n\n### consul.query.create(options)\n\nCreate a new prepared query.\n\nOptions\n\n- name (String, optional): name that can be used to execute a query instead of using its ID\n- session (String, optional): provides a way to automatically remove a prepared query when the given session is invalidated\n- token (String, optional): captured ACL Token that is reused as the ACL Token every time the query is executed\n- near (String, optional): allows specifying a particular node to sort near based on distance sorting using Network Coordinates\n- service.service (String, required): name of the service to query\n- service.failover.nearestn (Number, optional): when set the query will be forwarded to up to nearest N other datacenters based on their estimated network round trip time using Network Coordinates from the WAN gossip pool\n- service.failover.datacenters (String[], optional): fixed list of remote datacenters to forward the query to if there are no healthy nodes in the local datacenter\n- service.onlypassing (Boolean, default: false): filter results to only nodes with a passing state\n- service.tags (String[], optional): list of service tags to filter the query results\n- ttl.dns (String, optional, ex: `10s`): controls how the TTL is set when query results are served over DNS\n\nUsage\n\n```javascript\nawait consul.query.create({\n  name: 'redis',\n  service: {\n    service: 'redis'\n    onlypassing: true\n  },\n});\n```\n\nResult\n\n```json\n{\n  \"ID\": \"422b14b9-874b-4520-bd2e-e149a42b0066\"\n}\n```\n\n\u003ca id=\"query-update\"\u003e\u003c/a\u003e\n\n### consul.query.update(options)\n\nUpdate existing prepared query.\n\nOptions\n\n- query (String, required): ID of the query\n\nAnd all [create options][query-create].\n\nUsage\n\n```javascript\nawait consul.query.update({\n  query: '422b14b9-874b-4520-bd2e-e149a42b0066',\n  name: 'redis',\n  service: {\n    service: 'redis'\n    onlypassing: false\n  },\n});\n```\n\n\u003ca id=\"query-get\"\u003e\u003c/a\u003e\n\n### consul.query.get(options)\n\nGet prepared query.\n\nOptions\n\n- query (String, required): ID of the query\n\nUsage\n\n```javascript\nawait consul.query.get(\"6119cabf-c052-48fe-9f07-711762e52931\");\n```\n\nResult\n\n```json\n{\n  \"ID\": \"6119cabf-c052-48fe-9f07-711762e52931\",\n  \"Name\": \"redis\",\n  \"Session\": \"\",\n  \"Token\": \"\",\n  \"Template\": {\n    \"Type\": \"\",\n    \"Regexp\": \"\"\n  },\n  \"Service\": {\n    \"Service\": \"redis\",\n    \"Failover\": {\n      \"NearestN\": 3,\n      \"Datacenters\": [\"dc1\", \"dc2\"]\n    },\n    \"OnlyPassing\": false,\n    \"Tags\": [\"master\", \"!experimental\"]\n  },\n  \"DNS\": {\n    \"TTL\": \"10s\"\n  },\n  \"RaftIndex\": {\n    \"CreateIndex\": 23,\n    \"ModifyIndex\": 42\n  }\n}\n```\n\n\u003ca id=\"query-destroy\"\u003e\u003c/a\u003e\n\n### consul.query.destroy(options)\n\nDelete prepared query.\n\nOptions\n\n- query (String, required): ID of the query\n\nUsage\n\n```javascript\nawait consul.query.destroy(\"422b14b9-874b-4520-bd2e-e149a42b0066\");\n```\n\n\u003ca id=\"query-execute\"\u003e\u003c/a\u003e\n\n### consul.query.execute(options)\n\nExecute prepared query.\n\nOptions\n\n- query (String, required): ID of the query\n\nUsage\n\n```javascript\nawait consul.query.execute(\"6119cabf-c052-48fe-9f07-711762e52931\");\n```\n\nResult\n\n```json\n{\n  \"Service\": \"redis\",\n  \"Nodes\": [\n    {\n      \"Node\": {\n        \"Node\": \"foobar\",\n        \"Address\": \"10.1.10.12\",\n        \"TaggedAddresses\": {\n          \"lan\": \"10.1.10.12\",\n          \"wan\": \"10.1.10.12\"\n        }\n      },\n      \"Service\": {\n        \"ID\": \"redis\",\n        \"Service\": \"redis\",\n        \"Tags\": null,\n        \"Port\": 8000\n      },\n      \"Checks\": [\n        {\n          \"Node\": \"foobar\",\n          \"CheckID\": \"service:redis\",\n          \"Name\": \"Service 'redis' check\",\n          \"Status\": \"passing\",\n          \"Notes\": \"\",\n          \"Output\": \"\",\n          \"ServiceID\": \"redis\",\n          \"ServiceName\": \"redis\"\n        },\n        {\n          \"Node\": \"foobar\",\n          \"CheckID\": \"serfHealth\",\n          \"Name\": \"Serf Health Status\",\n          \"Status\": \"passing\",\n          \"Notes\": \"\",\n          \"Output\": \"\",\n          \"ServiceID\": \"\",\n          \"ServiceName\": \"\"\n        }\n      ],\n      \"DNS\": {\n        \"TTL\": \"10s\"\n      },\n      \"Datacenter\": \"dc3\",\n      \"Failovers\": 2\n    }\n  ]\n}\n```\n\n\u003ca id=\"query-explain\"\u003e\u003c/a\u003e\n\n### consul.query.explain(options)\n\nExplain prepared query.\n\nOptions\n\n- query (String, required): ID of the query\n\nUsage\n\n```javascript\nawait consul.query.explain(\"422b14b9-874b-4520-bd2e-e149a42b0066\");\n```\n\nResult\n\n```json\n{\n  \"Query\": {\n    \"ID\": \"422b14b9-874b-4520-bd2e-e149a42b0066\",\n    \"Name\": \"redis\",\n    \"Session\": \"\",\n    \"Token\": \"\",\n    \"Template\": {\n      \"Type\": \"\",\n      \"Regexp\": \"\"\n    },\n    \"Service\": {\n      \"Service\": \"redis\",\n      \"Failover\": {\n        \"NearestN\": 3,\n        \"Datacenters\": [\"dc1\", \"dc2\"]\n      },\n      \"OnlyPassing\": false,\n      \"Tags\": [\"master\", \"!experimental\"]\n    },\n    \"DNS\": {\n      \"TTL\": \"10s\"\n    },\n    \"RaftIndex\": {\n      \"CreateIndex\": 23,\n      \"ModifyIndex\": 42\n    }\n  }\n}\n```\n\n\u003ca id=\"session\"\u003e\u003c/a\u003e\n\n### consul.session\n\n- [create](#session-create)\n- [destroy](#session-destroy)\n- [get](#session-get)\n- [node](#session-node)\n- [list](#session-list)\n- [renew](#session-renew)\n\n\u003ca id=\"session-create\"\u003e\u003c/a\u003e\n\n### consul.session.create([options])\n\nCreate a new session.\n\nOptions\n\n- dc (String, optional): datacenter (defaults to local for agent)\n- lockdelay (String, range: 1s-60s, default: `15s`): the time consul prevents locks held by the session from being acquired after a session has been invalidated\n- name (String, optional): human readable name for the session\n- node (String, optional): node with which to associate session (defaults to connected agent)\n- checks (String[], optional): checks to associate with session\n- behavior (String, enum: release, delete; default: release): controls the behavior when a session is invalidated\n- ttl (String, optional, valid: `10s`-`86400s`): interval session must be renewed\n\nUsage\n\n```javascript\nawait consul.session.create();\n```\n\nResult\n\n```json\n{\n  \"ID\": \"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\"\n}\n```\n\n\u003ca id=\"session-destroy\"\u003e\u003c/a\u003e\n\n### consul.session.destroy(options)\n\nDestroy a given session.\n\nOptions\n\n- id (String): session ID\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.session.destroy(\"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\");\n```\n\n\u003ca id=\"session-get\"\u003e\u003c/a\u003e\n\n### consul.session.get(options)\n\nQueries a given session.\n\nOptions\n\n- id (String): session ID\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.session.get(\"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\");\n```\n\nResult\n\n```json\n{\n  \"CreateIndex\": 11,\n  \"ID\": \"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\",\n  \"Name\": \"\",\n  \"Node\": \"node1\",\n  \"Checks\": [\"serfHealth\"],\n  \"LockDelay\": 15000000000\n}\n```\n\n\u003ca id=\"session-node\"\u003e\u003c/a\u003e\n\n### consul.session.node(options)\n\nLists sessions belonging to a node.\n\nOptions\n\n- node (String): node\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.session.node(\"node1\");\n```\n\nResult\n\n```json\n[\n  {\n    \"CreateIndex\": 13,\n    \"ID\": \"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\",\n    \"Name\": \"\",\n    \"Node\": \"node1\",\n    \"Checks\": [\"serfHealth\"],\n    \"LockDelay\": 15000000000\n  }\n]\n```\n\n\u003ca id=\"session-list\"\u003e\u003c/a\u003e\n\n### consul.session.list([options])\n\nLists all the active sessions.\n\nOptions\n\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.session.list();\n```\n\nResult\n\n```json\n[\n  {\n    \"CreateIndex\": 15,\n    \"ID\": \"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\",\n    \"Name\": \"\",\n    \"Node\": \"node1\",\n    \"Checks\": [\"serfHealth\"],\n    \"LockDelay\": 15000000000\n  }\n]\n```\n\n\u003ca id=\"session-renew\"\u003e\u003c/a\u003e\n\n### consul.session.renew(options)\n\nRenew a given session.\n\nOptions\n\n- id (String): session ID\n- dc (String, optional): datacenter (defaults to local for agent)\n\nUsage\n\n```javascript\nawait consul.session.renew(\"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\");\n```\n\nResult\n\n```json\n[\n  {\n    \"CreateIndex\": 15,\n    \"ID\": \"a0f5dc05-84c3-5f5a-1d88-05b875e524e1\",\n    \"Name\": \"\",\n    \"Node\": \"node1\",\n    \"Checks\": [\"serfHealth\"],\n    \"LockDelay\": 15000000000,\n    \"Behavior\": \"release\",\n    \"TTL\": \"\"\n  }\n]\n```\n\n\u003ca id=\"status\"\u003e\u003c/a\u003e\n\n### consul.status\n\n- [leader](#status-leader)\n- [peers](#status-peers)\n\n\u003ca id=\"status-leader\"\u003e\u003c/a\u003e\n\n### consul.status.leader()\n\nReturns the current Raft leader.\n\nUsage\n\n```javascript\nawait consul.status.leader();\n```\n\nResult\n\n```json\n\"127.0.0.1:8300\"\n```\n\n\u003ca id=\"status-peers\"\u003e\u003c/a\u003e\n\n### consul.status.peers()\n\nReturns the current Raft peer set.\n\nUsage\n\n```javascript\nawait consul.status.peers();\n```\n\nResult\n\n```json\n[\"127.0.0.1:8300\"]\n```\n\n\u003ca id=\"transaction\"\u003e\u003c/a\u003e\n\n### consul.transaction.create(operations)\n\noperations: The body of the request should be a list of operations to perform inside the atomic transaction. Up to 64 operations may be present in a single transaction.\n\nUsage\n\n```javascript\nawait consul.transaction.create([\n  {\n    {\n      KV: {\n        Verb: 'set',\n        Key: 'key1',\n        Value: Buffer.from('value1').toString('base64')\n      }\n    },{\n      KV: {\n        Verb: 'delete',\n        Key: 'key2'\n      }\n    }\n  }\n]);\n```\n\n\u003ca id=\"watch\"\u003e\u003c/a\u003e\n\n### consul.watch(options)\n\nWatch an endpoint for changes.\n\nThe watch relies on blocking queries, adding the `index` and `wait` parameters as per [Consul's documentation](https://www.consul.io/docs/agent/http.html)\n\nIf a blocking query is dropped due to a Consul crash or disconnect, watch will attempt to reinitiate the blocking query with logarithmic backoff.\n\nUpon reconnect, unlike the first call to watch() in which the latest `x-consul-index` is unknown, the last known `x-consul-index` will be reused, thus not emitting the `change` event unless it has been incremented since.\n\nNOTE: If you specify an alternative options.timeout keep in mind that a small random amount of additional wait is added to all requests (wait / 16). The default timeout is currently set to (wait + wait \\* 0.1), you should use something similar to avoid issues.\n\nOptions\n\n- method (Function): method to watch\n- options (Object): method options\n- backoffFactor (Integer, default: 100): backoff factor in milliseconds to apply between attempts (`backoffFactor * (2 ^ retry attempt)`)\n- backoffMax (Integer, default: 30000): maximum backoff time in milliseconds to wait between attempts\n- maxAttempts (Integer): maximum number of retry attempts to make before giving up\n\nUsage\n\n```javascript\nconst watch = consul.watch({\n  method: consul.kv.get,\n  options: { key: \"test\" },\n  backoffFactor: 1000,\n});\n\nwatch.on(\"change\", (data, res) =\u003e {\n  console.log(\"data:\", data);\n});\n\nwatch.on(\"error\", (err) =\u003e {\n  console.log(\"error:\", err);\n});\n\nsetTimeout(() =\u003e {\n  watch.end();\n}, 30 * 1000);\n```\n\n## Acceptance Tests\n\n1.  Install [Consul][download] into your `PATH`\n\n    ```console\n    $ brew install consul\n    ```\n\n1.  Attach required IPs\n\n    ```console\n    $ sudo ifconfig lo0 alias 127.0.0.2 up\n    $ sudo ifconfig lo0 alias 127.0.0.3 up\n    ```\n\n1.  Install client dependencies\n\n    ```console\n    $ npm install\n    ```\n\n1.  Run tests\n\n    ```console\n    $ npm run acceptance\n    ```\n\n## License\n\nThis work is licensed under the MIT License (see the LICENSE file).\n\nParts of the Documentation were copied from the official\n[Consul website][consul-docs-api], see the NOTICE file for license\ninformation.\n\n[consul]: https://www.consul.io/\n[consul-docs-api]: https://www.consul.io/api-docs\n[download]: https://www.consul.io/downloads\n","funding_links":[],"categories":["JavaScript","Repository","Projects"],"sub_categories":["Distribute","Programming Language Clients"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilas%2Fnode-consul","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsilas%2Fnode-consul","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsilas%2Fnode-consul/lists"}