node proxy error Error: connect ECONNREFUSED

I use reverse proxy from the following module
https://github.com/nodejitsu/node-http-proxy

and I got in err for the following code

proxy.on('error', function (err, req, res) {
    res.end('Error occurr'+ err);
});

connect ECONNREFUSEDwhat does it mean this error and what can be possible solution to it?

I use the

proxy = httpProxy.createProxyServer({});

    proxy.web(req, res, {
        target: 'http://' + hostname + ':' + port
    });

    proxy.on('error', function (err, req, res) {
        res.end('Error occurr'+ err);
    });

and I need just to proxy calls to new port

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

ECONNREFUSED means there is no server process listening at the specified port. What hostname and port are you using? Can you connect directly (without the proxy)?

P.S. Unrelated to ECONNREFUSED, but you should also set changeOrigin in the options passed to proxy.web:

proxy.web(req, res, {
    target: 'http://' + hostname + ':' + port,
    changeOrigin: true
});

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply