node.js Error: connect ECONNREFUSED; response from server

I have a problem with this little program:

var http = require("http");
var request = http.request({
    hostname: "localhost",
    port: 8000,
    path: "/",
    method: "GET"
}, function(response) {
    var statusCode = response.statusCode;
    var headers = response.headers;
    var statusLine = "HTTP/" + response.httpVersion + " " +statusCode + " " + http.STATUS_CODES[statusCode];
    console.log(statusLine);
    for (header in headers) {
        console.log(header + ": " + headers[header]);
    }
    console.log();
    response.setEncoding("utf8");
    response.on("data", function(data) {
        process.stdout.write(data);
    });
    response.on("end", function() {
        console.log();
    });
});

The result in console is this:

events.js:141
      throw er; // Unhandled 'error' event
      ^

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

I do not understand why this happens.

89 thoughts on “node.js Error: connect ECONNREFUSED; response from server”

  1. I simply couldn’t depart your web site prior to suggesting that I really enjoyed the usual information an individual supply on your visitors? Is gonna be back steadily in order to check out new posts.

    Reply
  2. I really love your blog.. Great colors & theme. Did you develop this site yourself?
    Please reply back as I’m trying to create my own site and would like to know
    where you got this from or what the theme is called.
    Thank you!

    Reply
  3. You actually make it appear so easy together with your presentation but I find this matter to be actually one thing that I think I might by no means understand. It sort of feels too complicated and very extensive for me. I’m having a look forward for your subsequent post, I will attempt to get the grasp of it!

    Reply
  4. Pingback: herbal viagra
  5. Pingback: generic for viagra
  6. Pingback: otc viagra
  7. Pingback: drugs like cialis
  8. Pingback: cialis free trial
  9. Pingback: sildenafil viagra
  10. Pingback: order viagra
  11. Pingback: 29 dating 18 gay
  12. Pingback: cialis effects

Leave a Comment