Install Parse Server on Ubuntu 20.04

Parse Overview

Parse provides a cloud-based backend service to build data-driven mobile applications quickly. Initially developed by Facebook, Parse is a free and open-source Backend-as-a-Service (BaaS) platform which can be deployed to any infrastructure that runs NodeJS. It can be added to existing web applications, or run by itself. Parse server comes with a simple and easy-to-use web interface that can be used for data manipulation, to view analytics, and to schedule and send push notifications.

Requirements:

Installing MongoDB

MongoDB is a document-oriented database that is free and open-source. It considered one of the most popular NoSQL database engines because it is scalable, powerful, reliable and easy to use. In contrast to relational databases, MongoDB does not require a deep predefined schema before you can add data since it can be altered at any time.

1 . Update Ubuntu packet manager.

apt-get update

2 . Upgrade the Ubuntu packages already installed.

apt-get upgrade

3 . Install MongoDB. By default, MongoDB is available in the Ubuntu 20.04 default repository.

apt-get install mongodb-server -y

4 . Verify MongoDB status.

systemctl status mongodb

which returns:

● mongodb.service - An object/document-oriented database
     Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-11-03 15:43:50 UTC; 22s ago
       Docs: man:mongod(1)
   Main PID: 718 (mongod)
      Tasks: 23 (limit: 4915)
     Memory: 42.2M
     CGroup: /system.slice/mongodb.service
             └─718 /usr/bin/mongod --unixSocketPrefix=/run/mongodb --config /etc/mongodb.conf

Nov 03 15:43:50 scw-friendly-edison systemd[1]: Started An object/document-oriented database.

Installing NodeJS

By default, Node.js is not available in the Ubuntu 20.04 default repository. Therefore Node.js needs to be added to the repository of your system. In addition, ensure curl is installed on your system.

1 . Add an external repository for the required version of NodeJS. Make sure to replace lts by the lastest node runtime.

curl -sL https://deb.nodesource.com/setup_lts.x | bash -

2 . Install NodeJS

apt-get install nodejs -y

3 . Install yarn package manager.

npm install -g yarn

4 . Verify the NodeJS version.

node --version

which returns NodeJS lastest version:

v12.19.0

Installing Parse Server

1 . Install the parse-server module using the Yarn package manager.

yarn global add parse-server

which returns:

...
success Installed "parse-server@4.4.0" with binaries:
      - parse-server

2 . Create a Parse server configuration file and define the attributes of the parse server.

nano config.json

3 . Add the following lines:

{
  "appName": "Parse Server Application",
  "databaseURI": "mongodb://localhost:27017/parsedb",
  "appId": "SCWASRTWK9Y6AVMP3KFC",
  "masterKey": "LASDK823JKHR87SDFJSDHF8DFHASFDF",
  "serverURL": "https://localhost:1337/parse",
  "publicServerURL": "https://0.0.0.0:1337/parse",
  "port": 1337
}

The configuration details are as follows:

  • appName: Set any name for your Parse server
  • databaseURI: Connection string to the MongoDB database
  • appID: Set a random string as appID, which will be used to connect the server.
  • masterKey: Set a random string for the master key.
  • serverURL: Set a URL for your parse server
  • publicServerURL: Set a public URL for your parse server
  • port: Indicate the server port

4 . Save and close the file.

5 . Start the Parse server.

Note: The nohup command allows you to manually start the Parse server. However, the downside of this procedure is that if the instance on which the Parse server is installed fails, the Parse server will not restart automatically.

nohup parse-server config.json &

6 . As mentioned in the configuration file, the Parse server is listening on port 1337. To verify:

ss -ant | grep 1337

which returns

LISTEN  0       511            0.0.0.0:1337             0.0.0.0:*

Turning Parse Server into a Service with Systemd

Creating a systemd service file allows you to automatically run and manage your application. It will restart in case of a failure (unexpected exit), and even survive server restarts.

1 . From /etc/systemd/system/, create a file called parse.server.service

nano parse.server.service

2 . Copy the following lines

[Unit]
Description=Parse Server service
After=mongodb.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=ubuntu
ExecStart=/usr/local/bin/parse-server /ubuntu/config.json

[Install]
WantedBy=multi-user.target

The configuration details are as follows:

  • Description: Define a name for your service
  • After: Define after which service the application starts
  • User: Set your actual username
  • ExecStart: Set the proper path to your script

3 . Save and close the file.

4 . Start the Parse server.

systemctl start parse.server.service

5 . Verify the status of the Parse server.

systemctl status parse.server.service

which returns

Warning: The unit file, source configuration file or drop-ins of parse.server.service changed on disk. Run 'systemctl daemon-reload' to reload units.
● parse.server.service - Parse Server service
     Loaded: loaded (/etc/systemd/system/parse.server.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-11-10 12:28:20 UTC; 1h 13min ago
   Main PID: 18097 (node)
      Tasks: 11 (limit: 4915)
     Memory: 63.2M
     CGroup: /system.slice/parse.server.service
             └─18097 node /usr/local/bin/parse-server /root/config.json

6 . Get it to automatically start on boot.

systemctl enable parse.server.rervice

Configuring Parse Server Dashboard

Parse server comes with a Dashboard for managing your Parse server applications. It is accessible through a web browser.

1 . Install Parse dashboard.

yarn global add parse-dashboard

which returns:

success Installed "parse-dashboard@2.1.0" with binaries:
      - parse-dashboard

2 . Create a configuration file for the Parse dashboard.

nano parse-dashboard-config.json

3 . Add the following lines. Do not forget to replace your server IP address.

{
  "apps": [
    {
      "serverURL": "http://your-server-ip:1337/parse",
      "appId": "SCWASRTWK9Y6AVMP3KFC",
      "masterKey": "LASDK823JKHR87SDFJSDHF8DFHASFDF",
      "allowInsecureHTTP": "true",
      "appName": "ParseApp"
    }
  ],
 "users": [
    {
      "user":"scaler1",
      "pass":"scalewayrocks"
    }
  ],
  "iconsFolder": "icons"
}

The configuration details are as follows:

  • serverURL: Set a URL for your parse server
  • appID: Set a random string as appID, which will be used to connect the server.
  • masterKey: Set a random string for the master key.
  • appName: Set any name for your Parse server
  • user: Set the username to connect to the Parse Dashboard
  • pass: Set the password to connect to the Parse Dashboard

4 . Save and close the file.

5 . Start the Parse server Dashboard.

Note: The nohup command allows you to manually start the Parse server. However, the downside of this procedure is that if the instance on which the Parse server is installed fails, the Parse server will not restart automatically.

nohup parse-dashboard --dev --config parse-darshboard-config.json &

6 . The Parse server Dashboard is listening on port 4040. To verify:

ss -ant | grep 4040

which returns:

LISTEN  0       511            0.0.0.0:4040             0.0.0.0:*

Turning Parse Server Dashboard into a Service with Systemd

1 . From /etc/systemd/system/, create a file called parse.server.dashboard.service

nano parse.server.dashboard.service

2 . Copy the following lines:

[Unit]
Description=Parse Server Dashboard service
After=parse.server.service
StartLimitIntervalSec=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=ubuntu
ExecStart=/usr/local/bin/parse-dashboard --dev --config /ubuntu/parse-dashboard-config.json

[Install]
WantedBy=multi-user.target

In the example above, the After directive implies that the Parse server Dashboard service starts after the Parse server service itself.

3 . Start the Parse server Dashboard service.

systemctl start parse.server.dashboard.service

4 . Verify the status of the Parse server.

systemctl status parse.server.dashboard.service

which returns:

parse.server.dashboard.service - Parse Server Dashboard service
     Loaded: loaded (/etc/systemd/system/parse.server.dashboard.service; disabled; vendor preset: enabled)
     Active: active (running) since Tue 2020-11-10 12:39:56 UTC; 1h 17min ago
   Main PID: 18312 (node)
      Tasks: 11 (limit: 4915)
     Memory: 24.0M
     CGroup: /system.slice/parse.server.dashboard.service
             └─18312 node /usr/local/bin/parse-dashboard --dev --config /root/parse-darshboard-config.json

Accessing the Parse Server Dashboard

1 . Access the Parse server dashboard by visiting the URL http://your-server-ip:4040

2 . Add the credentials that you entered in the parse-darshboard-config.json file.

Discover the Cloud That Makes Sense