title: Load balancing with node.js using http-proxy
body: <p>I'm trying to code a load balancing with node.js and http-proxy. I want a loadBalancer that shares incoming request treatment between 2 servers.</p>
  <pre><code>var http = require('http'),
  httpProxy = require('http-proxy');
  
  var servers =  [{host :'127.0.0.1', port :3000}, {host : 'remote_adr',port :3000}];
  
  httpProxy.createServer(function (req, res, proxy) {
      var target = servers.shift();
      proxy.proxyRequest(req, res, target);
      servers.push(target);
  }).listen(8000);
  </code></pre>
  <p>I thought that doing this would have made a loadBalancer which sends requests alternately to serv1 and to serv2.</p>
  <p>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 ( 127.0.0.1:3000 )</p>
  <p>Is somebody able to explain that behavior?</p>