Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Node.js Error: connect ECONNREFUSED

I am new to node and running into this error on a simple tutorial.

I am on the OS X 10.8.2 trying this from CodeRunner and the Terminal. I have also tried putting my module in the node_modules folder.

I can tell this is some kind of connection problem but I have no idea why?

events.js:71         throw arguments[1]; // Unhandled 'error' event                        ^ Error: connect ECONNREFUSED     at errnoException (net.js:770:11)     at Object.afterConnect [as oncomplete] (net.js:761:19) 

app.js:

var makeRequest = require('./make_request');  makeRequest("Here's looking at you, kid"); makeRequest("Hello, this is dog"); 

make_request.js:

var http = require('http');  var makeRequest = function(message) {      //var message = "Here's looking at you, kid.";     var options = {         host: 'localhost', port: 8080, path:'/', method: 'POST'     }      var request = http.request(options, function(response) {         response.on('data', function(data) {             console.log(data);         });     });     request.write(message);     request.end(); };  module.exports = makeRequest; 
like image 622
ian Avatar asked Jan 05 '13 03:01

ian


People also ask

How do you fix Econnrefused error?

If that's the cause of the Error: Connect econnrefused – connection refused by server error, simply disable the firewall and anti-virus software on your computer and try to reconnect.

What is connect Econnrefused?

Enhancement Number. The ECONNREFUSED Connection refused by the server error, is a common error returned by the Filezilla FTP client. This error indicates that the user is trying to connect to your server and is unable to connect to the port. There are a few reasons the client would receive this error.

How long does it take for nodejs error connect econnrefused to work?

Here it's my success story with incredible persistant Node.js error connect ECONNREFUSED . Day 1. I run this code, and should work fine. Usual errors, maybe 3-4 minutes. I changed host: 'localhost' to host : '127.0.0.1', port: 8080, or maybe 8000, oh yes, 3306 this is.

What is the unhandledpromiserejectionwarning in NodeJS?

Failing on to connect to MySQL database exist on the following short description : UnhandledPromiseRejectionWarning: SequelizeConnectionRefusedError: connect ECONNREFUSED 127.0.0.1:3306 Furthermore, the following is the full output of the error message upon the NodeJS application execution :

What does econnrefused error code mean?

ECONNREFUSED error means that connection could not be made with the target service (in your case localhost:8080 ). Check your service running on port 8080. To know more about node.js errors, refer this doc.

What is unhandled error in Node JS?

The Unhandled 'error' event is referring not providing a function to the request to pass errors. Without this event the node process ends with the error instead of failing gracefully and providing actual feedback. You can set the event just before the request.write line to catch any issues: Show activity on this post.


2 Answers

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.

like image 52
user2957009 Avatar answered Sep 26 '22 23:09

user2957009


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.

like image 45
JakubKnejzlik Avatar answered Sep 26 '22 23:09

JakubKnejzlik