14

I have a simple Node.js bot that makes an HTTP request each second to a rest API.

If the returned data is right then I construct an URL where I HTTP POST.

Everything works alright but after ~4-5hrs of running I got this error

0|server   | error:  Error: getaddrinfo ENOTFOUND www.rest-api.com www.rest-api.com:443
0|server   |     at errnoException (dns.js:28:10)
0|server   |     at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:73:26)

Can someone explain to me why this has happened?

After I restart my server everything got working.

I'm using axios to make the http requests.

Anderson
  • 331
  • 1
  • 4
  • 18

4 Answers4

13

I met the same issue and solved it!

try:

sudo vi /etc/hosts

and add:

127.0.0.1 localhost

to hosts

olibiaz
  • 2,551
  • 4
  • 29
  • 31
William
  • 3,724
  • 9
  • 43
  • 76
7

The symptom is that the remote address cannot be resolved.

The cause could be many things. First, try to see if it's node specific by trying to resolve the address directly:

$ nslookup www.rest-api.com

Or:

$ dig www.rest-api.com

If that doesn't work, you've got a connectivity problem. It could be anything. Try looking at how long your DHCP lease lasts if you are using DHCP.

However if that does work fine but your node application still fails, you might be running into this: https://github.com/nodejs/node/issues/5436 , which is a bug in an underlying library. You can implement the workaround mentioned in that thread, which is specifying the IP version family through the following parameter { family: 4 } as a part of your request options.

arboreal84
  • 2,086
  • 18
  • 21
4

I had this issue becuase there was a typo in my URL - the path did not exist. Gotta be careful with long subdomain URLs. I discovered the issue while using the Postman Console - available by going to View > Show Postman Console.

CodeCaptain
  • 379
  • 4
  • 10
0

I got this error in Postman when I didn't have the Environment I wanted to use selected. The variables I was trying to call were therefore not defined.

voluntier
  • 330
  • 4
  • 11