Organizational Research By

Surprising Reserch Topic

load balancing with node js using http proxy

load balancing with node js using http proxy  using -'node.js,load-balancing,node-http-proxy'

I'm trying to code a loadbalancing with node.js and http-proxy. I want a loadBalancer which share incoming request treatment between 2 servers.

var http = require('http'),
httpProxy = require('http-proxy');

 var servers =  [{host :'', port :3000}, {host : 'remote_adr',port :3000}];

  httpProxy.createServer(function (req, res, proxy) {

  var target = servers.shift();
  proxy.proxyRequest(req, res, target);


I thought that doing this, it would have made a loadBalancer which send requests alternately to serv1 and to serv2.

However, when I try it out, it seems to request the 2 servers in no particular order. In addition most of the requests are sent to my localhost node server ( )

Is somebody able to explain that behavior ?

Thx a lot,


asked Oct 11, 2015 by 20shahi
0 votes

Related Hot Questions

1 Answer

0 votes
answered Oct 11, 2015 by rajesh