2

Is there a way to run multiple Parse server instance in one Node.js (one machine) environment? If yes, what would be the configuration.

I am specifically targeting for Jelastic, but I think general solution would be applicable anyway.

quarks
  • 33,478
  • 73
  • 290
  • 513

2 Answers2

2

I'm using this way and its working perfectly

// First app instance here

var api1 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev1',
  cloud: '/home/myApp/cloud/main1.js',
  appId: 'myAppId1',
  masterKey: 'myMasterKey1',
  fileKey: 'optionalFileKey1',
  serverURL: 'http://localhost:1337/parse'
});

// Second app instance here

var api2 = new ParseServer({
  databaseURI: 'mongodb://localhost:27017/dev2', // Connection string foryour MongoDB database
  cloud: '/home/myApp/cloud/main2.js', // Absolute path to your Cloud Code
  appId: 'myAppId2',
  masterKey: 'myMasterKey2', // Keep this key secret!
  fileKey: 'optionalFileKey',
 serverURL: 'http://localhost:1337/parse' // Don't forget to change to https if needed
});


// Serve the Parse API on the /parse URL prefix
var mountPath = process.env.PARSE_MOUNT || '/parse';

// Mount Apps here
app.use(mountPath, api1);
app.use(mountPath, api2);

Hope this helps!! Let me know

enter image description here

Maravilho Singa
  • 224
  • 3
  • 12
  • How does this work? You mounted both instances to the same place – OneCricketeer Dec 22 '16 at 21:28
  • I mounted in the same index.js file but they will me working separately Same Server_url but total deferents apps, just try to understand the code it's simple. – Maravilho Singa Dec 22 '16 at 21:34
  • No, I'm saying `app.use(mountPath, api2);` is at the same path as `api1`, so you no longer have any reference to `api1` – OneCricketeer Dec 22 '16 at 21:38
  • Yes you will. It's will work perfectly. Just try `var api1 = new ParseServer({ });` `var api2 = new ParseServer({ });` mount api1 and api2 – Maravilho Singa Dec 22 '16 at 21:44
  • Your `mountPath` doesn't change. I don't understand why it would work and you set both servers at `http://localhost:1337/parse`, so there would be a port binding conflict anyway. – OneCricketeer Dec 22 '16 at 21:50
  • I'm actualy using this method and i have 4 apps running perfectly. – Maravilho Singa Dec 22 '16 at 21:58
  • Look the image result that i added now in the answer, if is this that you want! – Maravilho Singa Dec 22 '16 at 22:02
  • @MaravilhoSinga is the Cloud code working fine? Based on the community feedback running multiple apps is okay but cause problem on Cloud codes – quarks Oct 14 '17 at 15:21
  • @xybrek it works fine, you need only to change cloud Code path for each app instance – Maravilho Singa Oct 14 '17 at 17:07
  • @MaravilhoSinga some say that problem will be on the Async cloud codes so it is not recommended to use cloud code in this scenario? – quarks Oct 15 '17 at 02:25
  • Also when using the `parse-server` from Github it uses CLI: `require("../lib/cli/parse-server");` how can your solution be adapted for this? – quarks Oct 15 '17 at 02:30
  • @xybrek Parse Server comes with necessary adapters, you don't need CLI to use Cloud Code, When you setup multiple apps in same index.js, they will not have same path since node.js takes care of it, each app instance will be used separately so you will need to path your cludcode files using different names ex: app 1 = ./cloud/main_1.js, app 2= ./cloud.main_2.js – Maravilho Singa Oct 19 '17 at 01:26
1

You can use the cluster module for running multiple instances of the same server application. Please note that there is no routing logic in Node.js, or in your program, and no shared state between the workers. Therefore, it is important to design your program such that it does not rely too heavily on in-memory data objects for things like sessions and login.

Aless
  • 289
  • 1
  • 9