Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Node.js dns.lookup() to internal docker-compose service

I’ve try yo measure DNS latency in my docker-compose/kubernetes cluster.

  setInterval(() => {
    console.time('dns-test');

    dns.lookup('http://my-service', (_, addresses, __) => {
      console.log('addresses:', addresses);
      console.timeEnd('dns-test');
    });
  }, 5000);

But get addresses: undefined, any ideas?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

...dns.lookup('http://my-service'...

The lookup function (with example usage) takes the first parameter as the host name that you want to lookup, eg. google.com. You should remove "http://" from the name you passed in.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading