silas / node-consul

Consul client
https://www.npmjs.com/package/consul
MIT License
560 stars 83 forks source link

how to watch service? #153

Closed tclxshunquan-wang closed 2 weeks ago

m00nst3r commented 3 months ago

I believe you already figured out this but still I think this should work for you

const consul = new Consul({})

 const watch = consul.watch({
  method: consul.health.service,
  options: {
    service: "service-name",
    tag: "dev",
  },
});

watch.on("change", data => {
    console.log(data)
});

watch.on("error", err => {
  console.log(err);
});