Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ECONNREFUSED error with node.js that does not occur in other clients

Tags:

http

node.js

I'm making an http request with the node.js client, and I get an ECONNREFUSED error. When I make what appears to be the same request with my browser or curl(1), it works just fine

Here's the node request:

var options = {   host: 'localhost',   port: 8080,   path: '/explorers/1.0/agegroup',   method: 'GET' };  var req = http.request(options, function(res) {   res.setEncoding('utf8');   res.on('data', function (chunk) {     console.log('BODY: ' + chunk);   }); });  req.on('error', function(e) {   console.log(e); });  req.end(); 

And it gives me the error:

{ [Error: connect ECONNREFUSED]   code: 'ECONNREFUSED',   errno: 'ECONNREFUSED',   syscall: 'connect' } 

But when I make the same request with a different client (curl in this case):

$ curl http://localhost:8080/explorers/1.0/agegroup {... response JSON ...} 

Other notes:

  • I've tried changing the host to www.google.com and the port to 80, and node makes the connection successfully

  • I've tried changing the port of the server, and I can still make requests with all clients but node.js (which still gets ECONNREFUSED)

  • The server to which I'm connecting is the CherryPy WSGI Server. When I try connecting to a node server at localhost:8080, it works fine, which would make me think it's the server's problem, except other clients work with the CherryPy server.

  • I've tried using the same headers that my browser is using, but that doesn't work, and it seems like the problem is at the TCP level anyway, so HTTP headers shouldn't be an issue.

What's wrong with my node request?

like image 433
aaronstacy Avatar asked May 17 '12 21:05

aaronstacy


People also ask

How do I fix error connect Econnrefused 127.0 0.1 8080?

You either need to start the server locally, since your request is going to localhost , or change localhost to the server´s URL or IP.

Why am I getting Econnrefused?

This can be for example a firewall, your Internet Service Provider (ISP), a typo in the URL, or the endpoint might be private. It can also be that the server IP address or the server's domain the request is trying to reach cannot be found.

What does error connect Econnrefused mean?

ECONNREFUSED means no process is listening at the given address and port.


1 Answers

I disagree with Soman's disagreement.

I've been pulling my hair out on this one, but yes, sure enough nodejs v0.10.24 and v0.10.25 refuse to connect to a PHP 5.4 development server (PHP's command line server) when invoked as:

php -S localhost:8088 

The browser, curl, everything else connects just fine. Yet, sure enough, changing the binding address to be:

php -S 127.0.0.1:8088  

And nodejs' using xmlrpc connects just fine. This occurred on a Mac OS X 10.9.1. Very odd.

like image 131
Steveorevo Avatar answered Sep 22 '22 09:09

Steveorevo