Running multiple Node (Express) apps on same port


I have multiple Node applications (build on Express framework).

Now I have placed them like this -

  • /var/www/app1
  • /var/www/app2
  • /var/www/app3

Now I want to run these 3 apps on the same port (say 8080). Is that possible ?

One thing to note is that, Each app has common routes like these -

  • app.get('/', func...);
  • app.get('/about', func...);
  •'/foo', func...);
  •'/bar', func...);

Basically I want to do it like you can do with Apache/PHP setup.

So with a LAMP stack when you have -

  • /var/www/app1
  • /var/www/app2
  • /var/www/app3

You can easily access them as different apps from -

  • localhost/app1
  • localhost/app2
  • localhost/app3
3/14/2016 5:43:11 PM

Accepted Answer

You can use app.use():

  .use('/app1', require('./app1/index').app)
  .use('/app2', require('./app2/index').app)
3/14/2016 5:41:37 PM

You could run them as seperate apps listening to different ports and then have a proxy (like ) serving everything on 8080 depending on the requested URL.


var options = {
  router: {
    '': '',
    '': '',
    '': ''

Works like charm for me ( I wasn't so keen on having them mounted as sub-apps, as suggested in the comments because i wanted them to run independently...

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow