node-consul icon indicating copy to clipboard operation
node-consul copied to clipboard

how to watch service?

Open tclxshunquan-wang opened this issue 2 years ago • 1 comments

tclxshunquan-wang avatar Sep 26 '23 03:09 tclxshunquan-wang

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);
});

m00nst3r avatar Aug 07 '24 12:08 m00nst3r