How to run multiple StrongLoop LoopBack apps on the same server?

loopbackjs, node.js, strongloop

Solution

Since LoopBack applications are regular Express applications, you can mount them on a path of the master app.

var app1 = require('path/to/app1');
var app2 = require('path/to/app2');

var root = loopback(); // or express();
root.use('/app1', app1);
root.use('/app2', app2);
root.listen(3000);

The obvious drawback is high runtime coupling between app1 and app2 - whenever you are upgrading either of them, you have to restart the whole server (i.e. both of them). Also a fatal failure in one app brings down the whole server.

The solution presented by @fiskeben is more robust, since each app is isolated.

On the other hand, my solution is probably easier to manage (you have only one Node process instead of nginx + per-app Node processes) and also allows you to configure middleware shared by both apps.

var root = loopback();
root.use(express.logger());
// etc.

root.use('/app1', app1);
root.use('/app2', app2);
root.listen(3000);

Problem

I'm currently running two StrongLoop LoopBack apps (Nodejs apps) on a single server with different ports. Both apps were created using `slc lb project` and `slc lb model` from the command line. Is it possible to run these apps on a single ports with different path and/or subdomain? If it is, how do I do that on a Linux machine? Example: `http://api.server.com:3000/app1/` for first app. `http://api.server.com:3000/app2/` for second app. thanks.

Original source