Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

getaddrinfo ENOENT error from HTTP request on Node.js [duplicate]

Below is the code for my Node.js HTTP response requester.

Once I use a website that I explicitly know does not exist, the error message would notify me the error: getaddrinfo ENOENT

I want to know more about this error. What spawns it? What's the detail of the error? Would 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);
};
like image 892
theGreenCabbage Avatar asked Mar 20 '13 15:03

theGreenCabbage


1 Answers

You can do this to get more details about error.

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

If you give a non-existent url then above code returns :

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

The error is thrown from http.ClientRequest class by http.request(). No a 404 will not generate this error. Error 404 means that the client was able to communicate with the server, but the server could not find what was requested. This error means Domain Name System failed to find the address (dns.js is for NAPTR queries).

like image 183
user568109 Avatar answered Nov 14 '22 23:11

user568109