Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Troubleshooting Error: connect ECONNREFUSED in nodejs stream-adventure tutorial

I've been working through the learnyoujs and stream-adventure tutorials:

https://github.com/substack/stream-adventure

https://github.com/rvagg/learnyounode#learn-you-the-nodejs-for-much-win

I've gotten all the way through the first set and most of the way thorough the second, but I keep getting an odd error... usually I can get it to go away.

Here's the command/error:

DEV/javascript/streamAdventure » stream-adventure run httpserver.js

stream.js:94
  throw er; // Unhandled stream error in pipe.
        ^
Error: connect ECONNREFUSED
  at errnoException (net.js:901:11)
  at Object.afterConnect [as oncomplete] (net.js:892:19)

This will launch but not kill the process for node, so I ps aux | grep node and then find the process and kill it.

Here's the "working" code from the tutorial:

var http = require('http');
var through = require('through');

var server = http.createServer(function (req, res) {
    if (req.method === 'POST') {
        req.pipe(through(function (buf) {
            this.queue(buf.toString().toUpperCase());
        })).pipe(res);
    }
    else res.end('send me a POST\n');
});
server.listen(8000);

If I just run nod httpserver.js and then curl at it, it works fine.... so does anyone have any insight into what is causing this error?

like image 247
John Reeve Avatar asked Aug 15 '13 16:08

John Reeve


1 Answers

There is a pull request to fix this, here: https://github.com/substack/stream-adventure/pull/16

Try to listen on port 8001 instead and rerun verify after closing all processes listening on 8000.

like image 78
zubinmehta Avatar answered Oct 03 '22 09:10

zubinmehta