1

I am trying to make an api call to my localhost but I always get Error: connect ECONNREFUSED 127.0.0.1:5005 at Object.exports._errnoException (util.js:1022:11)

var url = `http://127.0.0.1:5005/api/entities/myEndpoint?id=121`;
var options = {
      url: url
    };
request.get(options, function(err, response, body) {
  console.log(err, response,body);
});

It does work if I use an IP instead of localhost

1 Answers1

1

Check if your server has bound the port to its external IP only. On Linux, check netstat -tulpen | grep 5005. The output will contain the Server's listener address, e.g. 0.0.0.0:5005 or ::5005 both means that the server listens on all Interfaces for port 5005.

If your result is something like <ip address>:5005 where ip address is different from 127.0.0.1 that means that the server listens on that ip and port combination only and cannot be accessed using localhost, even if you are logged into the server.

mottek
  • 929
  • 5
  • 12