1

When I try to hit the endpoint from node.js, I am getting the following error.

Error: getaddrinfo ENOTFOUND developers.zomato.com developers.zomato.com:80
        at errnoException (dns.js:27:10)
        at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:78:26)

However, I am able to successfully hit the same endpoint from Postman. I looked up this error on SO and tried various solutions(like, here and here) but could not make it work. Here, is my code :

var http = require('http');

var latitude = "some_latitude";
var longitude = "some_longitude";
var userKey = "some_userKey";

var options = {
    host: 'developers.zomato.com',
    path: '/api/v2.1/geocode?lat=' + latitude + '&lon=' + longitude,
    method: 'GET',
    headers: {
        'user-key': userKey
  },
    agent: false
};

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

Please suggest where I might be going wrong or a way out of this. Thanks for reading !

Community
  • 1
  • 1
Shashank Goyal
  • 153
  • 1
  • 5
  • Prefix the `host` with "http://" or "https://". – str Jan 18 '17 at 15:35
  • @str afaik, we are not supposed to prefix host with that. Anyways, I tried that, but it's not working. – Shashank Goyal Jan 18 '17 at 15:41
  • 1
    Why do you think so? Even the [documentation](https://nodejs.org/api/http.html#http_http_get_options_callback) added the protocol to the host. – str Jan 18 '17 at 15:45
  • @str I tried it that way, but it doesn't seem to work. I also tried to set the "protocol" field in options, but to no avail. – Shashank Goyal Jan 18 '17 at 15:51
  • 1
    Have you tried using the node package 'https' instead? From your request you can see that you're hitting port 80. Have you verified port 80 is open? https usually uses port 443. I would do the following: use the node https package, and prepend https:// to your url. See what ports are open for that url, there are many tools that can do that. – Max Paymar Jan 18 '17 at 18:39
  • @MaxPaymar , I checked and both 80 and 443 ports are open. Prepending protocol to host url isn't working. I had already tried that on str's suggestion. – Shashank Goyal Jan 19 '17 at 05:17
  • Problem was because I was behind a corporate proxy. The similar code is working for me in my home system. – Shashank Goyal Jan 19 '17 at 20:43

0 Answers0