Parse Server and Dashboard on Ubuntu

1/14/17 — Updated for MongoDB 3.4
6/17/18 - Updated for MongoDB 3.6, Node 8, fixed URLs

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
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;

Define your Application

var myApplication = new ParseServer({
databaseURI: ‘mongodb://localhost:27017/myapp’,
appId: ‘AppID’,
masterKey: ‘MasterKey’,
serverURL: ‘https://localhost:1234/myapp'
});
  • 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
});

Setup SSL Certificate

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

Setup App URLs

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

Start the Server

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

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
pm2 start index.js
pm2 startup
pm2 save
  • pm2 stop|start|restart x|all – stop, start, or restart process x or all processes

--

--

https://atodd.io

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store