node.jshttpdnsrequestip

Node override request IP resolution


I'm struggling to find the correct terminology to accurately phrase this problem, but I'm gonna give it my best shot:

In node.js, is there a way to manually override the IP address when making an HTTP request (e.g. request some-domain.com/whatever and instead of resolving the IP address through DNS, manually provide some IP address 1.2.3.4) ?

This would, effectively speaking, be the equivalent of setting 1.2.3.4 some-domain.com in /etc/hosts


Solution

  • There is a tiny module that does exactly that: evil-dns.

    evilDns.add('foo.com', '1.2.3.4');