Node.js http getaddrinfo ENOTFOUND

I had this code snippet (slightly modified from how to make external http requests with node.js):

var http = require('http');

var options = {
  host: 'http://api.untappd.com/',
  port: 80,
  path: '/v4/user/info/rdehler?...'
};

http.get(options, function(resp){
  resp.on('data', function(chunk){
    //do something with chunk
  });
}).on("error", function(e){
  console.log("Got error: " + e.message);
});

and I was given this error:

Express server listening on port 3000

events.js:72
throw er; // Unhandled ‘error’ event
^
Error: getaddrinfo ENOTFOUND
at errnoException (dns.js:37:11)
at Object.onanswer [as oncomplete] (dns.js:124:16)

Pretty dumb, the error explains the issue pretty clearly. ‘http://api.untappd.com/’ is not a valid hostname to pass into options.host, whereas ‘api.untappd.com’ is a valid hostname. Duh moment of the day.

This entry was tagged . Bookmark the permalink.

One Response to Node.js http getaddrinfo ENOTFOUND

  1. Thanks!

    Actually had me stumped too for a bit.
    It works fine even with HTTPS as the target.

Comments are closed.