Node.js Error: connect ECONNREFUSED
Chances are you are struggling with the node.js dying whenever the server you are calling refuses to connect. Try this:
process.on('uncaughtException', function (err) {
console.log(err);
});
This keeps your server running and also give you a place to attach the debugger and look for a deeper problem.
I was having the same issue with ghost and heroku.
heroku config:set NODE_ENV=production
solved it!
Check your config and env that the server is running on.
You're trying to connect to localhost:8080 ... is any service running on your localhost and on this port? If not, the connection is refused which cause this error. I would suggest to check if there is anything running on localhost:8080 first.
You need to have a server running on port 8080 when you run the code above that simply returns the request back through the response. Copy the code below to a separate file (say 'server.js') and start this server using the node command (node server.js). You can then separately run your code above (node app.js) from a separate command line.
var http = require('http');
http.createServer(function(request, response){
//The following code will print out the incoming request text
request.pipe(response);
}).listen(8080, '127.0.0.1');
console.log('Listening on port 8080...');