Running multiple Node (Express) apps on same port

You could run them as seperate apps listening to different ports and then have a proxy (like https://github.com/nodejitsu/node-http-proxy/ ) serving everything on 8080 depending on the requested URL.

like:

var options = {
  router: {
    'foo.com/baz': '127.0.0.1:8001',
    'foo.com/buz': '127.0.0.1:8002',
    'bar.com/buz': '127.0.0.1:8003'
  }
};

Works like charm for me ( http://nerdpress.org/2012/04/20/hosting-multiple-express-node-js-apps-on-port-80/). I wasn't so keen on having them mounted as sub-apps, as suggested in the comments because i wanted them to run independently...


You can use app.use():

app
  .use('/app1', require('./app1/index').app)
  .use('/app2', require('./app2/index').app)
  .listen(8080);