Parse Server and Dashboard on Ubuntu

Alex Todd
5 min readJan 7, 2017
1/14/17 — Updated for MongoDB 3.4
6/17/18 - Updated for MongoDB 3.6, Node 8, fixed URLs

TLDR Script

For this tutorial, I’ll be covering how to setup Parse Server and Parse Dashboard so that they run on the same server and port and use SSL encryption.

Parse is a Node.js MBaaS (Mobile Backend-as-a-Service) that runs on the Express Web Framework. Parse has 9 software development kits for just about anything your app will run on. When Parse was first released it was a hosted service with plans for requests over time. After Facebook purchased Parse for $85 million in 2013, it decided to shut down the service in 2016 with the final servers going offline January 28, 2017. For the over 500,000 applications Parse hosted, Facebook open-sourced the server and dashboard to the community. In March 2016, Microsoft announced that Azure would have pre-made Parse instances.

Note: If you don’t have at least 1GB of RAM available, setup a swapfile or get more RAM. If you don’t have enough memory some commands won’t be able to finish.

Install MongoDB

To get started we’ll need to import the Mongo public key to our machine and create a list file for the repository. Then we’ll update our sources and install.

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.listsudo apt update
sudo apt install -y mongodb-org
sudo systemctl start mongod

Install Node.js

Now we need to setup Node.js, the program that Parse runs on. Let’s add the Node repository to our server and install it, along with a few dependencies. We’ll also upgrade npm to the latest version.

curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejs python build-essential libkrb5-dev
npm i npm@latest

Install PM2 Globally

PM2 is a Node processes manager that will let us keep our app up and running, even after a server reboot.

sudo npm install -g pm2

Setup and Configure Parse

Let’s start by cloning the Parse Server Example to our server, navigating to the server example, and setup NPM (Node Package Manager):

git clone git@github.com:parse-community/parse-server-example.git
cd parse-server-example
npm install
npm install parse-dashboard@latest --save

Now we need to edit the index.js file and setup our applications and the dashboard. Below I’ll walk through an example configuration.

var fs = require(‘fs’);
var http = require(‘http’);
var https = require(‘https’);
var express = require(‘express’);
var ParseServer = require(‘parse-server’).ParseServer;
var ParseDashboard = require(‘parse-dashboard’);
var app = express();
var port = 1234;
var myApplication = new ParseServer({
databaseURI: ‘mongodb://localhost:27017/myapp’,
appId: ‘AppID’,
masterKey: ‘MasterKey’,
serverURL: ‘https://localhost:1234/myapp'
});
var dashboard = new ParseDashboard({
“apps”: [{
“serverURL”: “https://localhost:1234/myapp",
“appId”: “AppID”,
“masterKey”: “MasterKey”,
“appName”: “My Cool App”
}],
“users”: [{
“user”: “username”,
“pass”: “pa$$w0rd”,
“apps”: [{“appId”: “AppID”}]
}],
“useEncryptedPasswords”: true
});
var cert = {
key: fs.readFileSync(‘privkey.pem’, ‘utf8’),
cert: fs.readFileSync(‘fullchain.pem’, ‘utf8’),
};
app.use(‘/dashboard’, dashboard);
app.use(‘/myapp’, myApplication);
var server = https.createServer(cert, app).listen(port, function() {
console.log(“Parse listening on port “ + port);
});

The Setup

var fs = require(‘fs’);
var http = require(‘http’);
var https = require(‘https’);
var express = require(‘express’);
var ParseServer = require(‘parse-server’).ParseServer;
var ParseDashboard = require(‘parse-dashboard’);
var app = express();
var port = 1234;

The above lines import requirements to run Parse and the only thing you need to change is the port number. You can use 1234 or any other port that isn’t being used by other services like Apache or NGINX.

Define your Application

var myApplication = new ParseServer({
databaseURI: ‘mongodb://localhost:27017/myapp’,
appId: ‘AppID’,
masterKey: ‘MasterKey’,
serverURL: ‘https://localhost:1234/myapp'
});

myApplication defines a Parse application that will run on your server. You can configure as many of these as you’d like. For each application change the following lines:

  • databaseURI: The url of the database for the application. If you leave this the same for multiple apps, all of your data will show up in every application.
  • appID: A unique identifier for the application.
  • masterKey: A unique and super secret key for the application.
  • serverURL: The public url that you will be able to use for API calls.

Setup the Dashboard

var dashboard = new ParseDashboard({
“apps”: [{
“serverURL”: “https://localhost:1234/myapp",
“appId”: “AppID”,
“masterKey”: “MasterKey”,
“appName”: “My Cool App”
}],
“users”: [{
“user”: “username”,
“pass”: “pa$$w0rd”,
“apps”: [{“appId”: “AppID”}]
}],
“useEncryptedPasswords”: true
});

These lines setup the dashboard. Apps is an array of the applications you want to see in the dashboard. Just copy and paste everything from when you defined your application and set an appName. Users is an array of users that will have access to the dashboard. If authentication on the dashboard fails, it will redirect to an empty dashboard. Fill in the user and pass. Passwords can be stored in plaintext (please don’t ever do this) or can be encrypted using a Bcrypt Generator. If you do encrypt your passwords, make sure to set useEncryptedPasswords to true.

Setup SSL Certificate

var cert = {
key: fs.readFileSync(‘privkey.pem’, ‘utf8’),
cert: fs.readFileSync(‘fullchain.pem’, ‘utf8’),
};

This snippet points to your private key and certificate files. Make sure that the permissions for the keys will allow Parse to access them. If permissions are not set correctly, Parse will throw an error and stop running. LetsEncrypt certificates are fully compatible with this.

Setup App URLs

app.use(‘/dashboard’, dashboard);
app.use(‘/myapp’, myApplication);

In order to have Node listen for specific urls define them by using app.use with the first parameter being the link and the second parameter being the application to host at that link. For example app.use(‘/dashboard’, dashboard); sets up the Parse Dashboard at https://localhost:1234/dashboard, as defined above. Be sure to setup a link for every application on your Parse server.

Start the Server

var server = https.createServer(cert, app).listen(port, function() {
console.log(“Parse listening on port “ + port);
});

Now we need to actually start the server. The above lines starts the https server with the certificate information and express on the port specified. If the application starts successfully, it will output “Parse listening on port 1234”.

Setup Firewall Rules

We need to allow Mongo and Parse through the server firewall so that they are accessible. To do this use the following commands. By default Mongo runs on port 27017. If you use a different port for Parse be sure to use the correct port when setting the firewall rules.

sudo ufw allow 1234/tcp
sudo ufw allow 27017/tcp

Start Parse

To start Parse in the current session run the following line. It is useful to check and confirm that the configuration is working.

npm start index.js

To start Parse and have it continually run and auto restart when the server is rebooted, run the following commands:

pm2 start index.js
pm2 startup
pm2 save

If you get an error message after running pm2 startup, run the command in the error message.

Other useful PM2 commands:

  • pm2 status – check the status of all running pm2 processes
  • pm2 stop|start|restart x|all – stop, start, or restart process x or all processes

Enjoy your Parse server!

--

--