0

When I run app.js, I get this error:

MBPdiDaniele3:Desktop danielemartini$ node app.js 
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: connect ECONNREFUSED 127.0.0.1:8080
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1063:14)
MBPdiDaniele3:Desktop danielemartini$ 

Here's the code for make_request.js:

var http = require('http');

var makeRequest = function(message) {

    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;

Here's the code for app.js:

var makeRequest = require('./make_request');

makeRequest("Here's looking at you, kid");
makeRequest("Hello, this is dog");
4
  • 2
    And... What's your question? Commented Jan 24, 2016 at 12:27
  • 1
    Maybe it's because you don't have anything listening on port 8080. Commented Jan 24, 2016 at 12:29
  • Make sure no other services are running port 8080 (Tomcat or a previous version of your service.) Commented Jan 24, 2016 at 13:15
  • Make sure something IS running on port 8080 since that's what you are connecting to Commented Jan 24, 2016 at 13:45

1 Answer 1

1

There are several possible causes :

  1. No service is running on localhost:8080
  2. A service runs on 8080 which refuses connections actively.

To check what is running, use one of those 2 commands (Unix) :

  • lsof -i :8080 -S
  • netstat -a | grep 8080

3 - Your running service isn't bound to your internal IP.

I've encountered the issue a few times on Cloud servers, where localhost/127.0.0.1 are not recognized. Try using the external IP of your machine (and make sure the firewall lets you make requests), or force your service to bind to all interfaces.

Hope it helps.

Sign up to request clarification or add additional context in comments.

3 Comments

This is not an answer this is guessing and general debugging instructions
@Jarrod_Roberson: This may not be the answer but it is helpful and therefore useful.
@JarrodRoberson Isn't Stack Overflow about helping users? There are 3 possible answers to this question, and following my informations should help OP solve his problem. If anything, the question may need to be rewritten to include 'I've tried this and that', therefore removing the guessing element.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.