Getaddrinfo ENOENT Error from HTTP Request on Node.js

Below is the code of my Node.js HTTP response request.

As soon as I use a site that I clearly know does not exist, the error message will notify me of the error: getaddrinfo ENOENT

I want to know more about this error. What causes this? What is the error detail? Will 404 'spawn it?

 var hostNames = ['www.pageefef.com']; for (i; i < hostNames.length; i++){ var options = { host: hostNames[i], path: '/' }; (function (i){ http.get(options, function(res) { var obj = {}; obj.url = hostNames[i]; obj.statusCode = res.statusCode; // obj.headers = res.headers; console.log(JSON.stringify(obj, null, 4)); }).on('error',function(e){ console.log("Error: " + hostNames[i] + "\n" + e.message); }); })(i); }; 
+7
source share
1 answer

You can do this to get more error information.

 .on('error',function(e){ console.log("Error: " + hostNames[i] + "\n" + e.message); console.log( e.stack ); }); 

If you specify a non-existent URL, the code is returned:

 getaddrinfo ENOTFOUND Error: getaddrinfo ENOTFOUND at errnoException (dns.js:37:11) at Object.onanswer [as oncomplete] (dns.js:124:16) 

The error is called from the http.ClientRequest class at http.request (). No 404 will generate this error. Error 404 means that the client was able to contact the server, but the server could not find the requested one. This error means that the domain name system could not find the address (dns.js for NAPTR ).

+8
source

All Articles