0

I try to request external url from my nodejs application, instead of getting json as response, i get an dns.js error, may be some of you have already faced this issue and have any solution ?

/* The request */
request = require('request');
const options = {
     url: 'http://my_url_host',
     port: 8188,
     path: `/shop`,
     qs: { id:5 }
};

request.get(options, function(response){
    console.log(response);
})

The console output :

0|server   | { Error: getaddrinfo ENOTFOUND my_url_host 
my_url_host:80
0|server   |     at errnoException (dns.js:55:10)
0|server   |     at GetAddrInfoReqWrap.onlookup [as oncomplete] 
(dns.js:97:26)
0|server   |   code: 'ENOTFOUND',
0|server   |   errno: 'ENOTFOUND',
0|server   |   syscall: 'getaddrinfo',
0|server   |   hostname: 'my_url_hostr',
0|server   |   host: 'my_url_host',
0|server   |   port: 80 }

Someone could help me please? i already search over google without success.

Thank you.

2 Answers2

0

This error comes when Node can not map URL to ip address. The probable resoans can be

  1. You have lost the internet connectivity.
  2. URL you have provided is not valid.
  3. Something is wrong with your DNS server.
Nitin Bhapkar
  • 346
  • 2
  • 7
  • i have internet connectivity, url works well in a browser, may be dns server ? –  Jun 29 '18 at 07:45
0

You are trying to access a url on port 8188 so make sure that the host, http://my_url_host, has actually open port 8188 and is actually listening, or that port 8188 is forwarded to 80 or 8080 for http calls.

Have you checked in your browser by visiting http://my_url_host:8188?

Check that you haven't mispelled your hostname (my_url_hostr as to my_url_host) anywhere. This is from your console output:

0|server   |   hostname: 'my_url_hostr',
Harry Theo
  • 784
  • 1
  • 8
  • 28
  • Hi, thanks for response, the url works on browser perfectly, but not with the nodejs request module –  Jun 29 '18 at 07:44
  • ok this seems to be an issue for a number of node versions. Did you have a look at this [thread](https://github.com/nodejs/node-v0.x-archive/issues/5488)? there are a number of things you can try – Harry Theo Jun 29 '18 at 10:46