Run Multiple Apps on One Parse-Server

Running multiple apps on one Parse-server, also called multi-app tenancy, is not supported by default. If you define multiple apps in parse-configuration file, while starting the instance, Parse-server log complains about app startup. Simply, App startup fails with bunch of error messages thrown and stating Multi-App Tenancy is not allowed.

So what is the workaround?

Luckily, there is a workaround to achieve this goal and that is to use PM2 which is an advanced process manager for Node.js. There are various useful features in PM2 for your Node apps, such as clustering, but we will talk about  our goal of running multiple apps on one parse server.

Installation.

pm2 is easy to install using npm.

npm install pm2 -g

Once installed, a sample configuration file can be initialized and used for personal reference. This file is called “ecosystem.js” and will be generated in pwd.

pm2 init

Defining multiple apps in configuration file

initialized file (ecosystem.js) already gives you some sample data to be used for reference. This is totally, up to you that if you want to define your own configuration. Following example shows 3 Application running in total, from which 2 are running on the same parse-server (localhost) and the third is Parse-Dashboard (also hosted on localhost).

Important part to note is that each application in Parse-Server has its own database URI "PARSE_SERVER_DATABASE_URI" and server port number i.e. "PORT": "8080". Two different applications cannot use same port, as the instance will report, “Port already in use” error message.

module.exports = {
apps : [
{
//Parse server configuration for App1
name : 'App 1',
script : 'parse-server',
env: {
"PARSE_SERVER_DATABASE_URI": "mongodb://localhost/app1db",
"PARSE_SERVER_APPLICATION_ID": "AppId",
"PARSE_SERVER_MASTER_KEY": "masterKey",
"PORT": "8080",
"PARSE_SERVER_URL": "http://localhost:8080/parse",
},
},
// parse server for App2
{
name : 'App2',
script : 'parse-server',
env: {
"PARSE_SERVER_DATABASE_URI": "mongodb://localhost/test",
"PARSE_SERVER_APPLICATION_ID": "AppId",
"PARSE_SERVER_MASTER_KEY": "masterKey",
"PORT": "1337",
"PARSE_SERVER_URL": "http://localhost:1337/parse",
},
},
//parse dashboard
{
name : 'DASHBOARD',
script : 'parse-dashboard',
"watch" : true,
"merge_logs" : true,
"cwd" : "/usr/local/bin/",
"args" : "--config /Users/gsingh/parsedashboard.json"
},
]
};

Additionally, You need to define any other application script, mentioned in args i.e. "--config /Users/gsingh/parsedashboard.json".

Run Multiple Apps

once everything is in place, we can start the apps using pm2 start <filename.js> command

run multiple apps on parse-server

That’s it. Once you see the status online, you should be able to navigate to the Parse Dashboard (or any other app)

parse-dashboard
parse-dashboard running on Node.js

I hope this helps. Please post any comments or thoughts. Happy Coding 🙂

Share your thoughts

*