Not sure if this is applicable in 2019… but I’m cleaning out my notes and came across something I wrote up on installing Parse (alternative to something like Firebase for budget minded builds)

The hosted parse.com service we’ve all come to know and love is dead as Jan 1 this year.  For most developers that means building future applications with Firebase, simply because it’s easy for you to setup an app and get going all on (now google’s ) infrastructure.  This is awesome of course but now it puts the fate of your application’s data in the hands of google. Prices could change, unapologetic outages could occur etc. Being a linux sysadmin at heart, I’d rather run my own servers.   

 

Naturally when I found out parse-server had been open sourced I gave it a shot and have been using it as a backend for my apps ever since.  Writing your own API is a pain, and the parse project is well cared for and makes life easier. And even better you can run it on cheap VPS, and scale ‘reasonably’ easy.  I say reasonably because parse-server currently doesn’t have a clustering mode, but you can still use Db Sharding for the mongodb datastore and scale that way.

 

The other great thing I enjoy about parse is that it’s essentially no sql access to a relational database.  Unlike firebase which is true nosql, parse lets you have tables, foreign keys ( they call them just pointers) etc. 

 

Dashboard –  There’s also an open source dashboard to show you your parse classes and data easily. This tutorial will cover how t to get that up and running as well.  It caused me some headaches when I first started but hopefully this guide will clear up any problems you may encounter.

 

Let’s get on to installation at setup.

 

Architecture Overview.

 

Install mongodb

 

There’s a good doc on intalling this here.

https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-14-04

 

The basic steps are:

 

Add the mongodb public key to your box.  This will allow you to pull the latest mongodb version from their repositories

 

sudo apt-key adv –keyserver hkp://keyserver.ubuntu.com:80 –recv 7F0CEB10

 

Then create a list file with the canned command from mongodb

echo “deb http://repo.mongodb.org/apt/ubuntu “$(lsb_release -sc)”/mongodb-org/3.0 multiverse” | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

 

Update apt

 

apt-get update

 

Now install mongodb

 

sudo apt-get install -y mongodb-org

 

Depending on your version of mongodb, you will need to add a user so for parse to be able to access the database securly.

 

Add a user addUser or createUser depending on version of it

 

3.xx

use parsedb

 

> db.createUser({ user: “mongo-user”, pwd: “pasword here”, roles:[“dbAdmin”]})

Successfully added user: { “user” : “mongo-user”, “roles” : [ “dbAdmin” ] 

 

2.4

 db.addUser( { user: “robochef-mongo”, pwd: “JSXkitxwqPpIznF”, roles: [ “dbAdmin” ] })

db.createUser

 

Test connection:  You can quickly make sure the user add went well by connecting to your database through the command line.

 

mongo localhost/yourdb -u your-mongo-user -p your-password 

MongoDB shell version: 2.4.9

connecting to: localhost/robochef

 

Protect db by making sure firewall is on.  Ufw

If you’re building a production box, I’d run ufw and be sure to allow traffic on ports 443/80.  Depending on your parse server config with nginx you can open up 1337 too (but not necessary).

That’s it for the database!  Now let’s install parse server.

 

Install parse server

 

The below guide shows you how to install all the necessary dependencies and parse server itself.  It’s very detailed and I recommend reading through it.

 

https://www.digitalocean.com/community/tutorials/how-to-run-parse-server-on-ubuntu-14-04

 

After installing NodeJS, clone the parse example server 

 

git clone https://github.com/ParsePlatform/parse-server-example.git

 

cd into parse-server-example

 

npm install

 

If all goes well you should have a ready to go parse server example.

 

The next step is to add your database query string into the index.js file of parse-server-example

This will allow parse to connect to your database and build the data structs it needs to.

 

Add query string for mongodb inrto index.js

It should look something like this:

 

var databaseUri = ‘mongodb://user-mongo:password-here@localhost:27017/your-database’

 

That’s it!  Parse is now effectively set up for querying/inserting data.  

 

Create an upstart server for it

You probably want to run Parse as a continuous service.  You can do this with pm2. 

Install pm2

npm install -g pm2

 

pm2 start npm — start

 

## launches app as ‘npm’  name

 

Add an Nginx front end if you want nginx to handle the connections from clients for you.

 

Parse Dashboard

One of the best features of the Parse.com service was being able to see all of your relational data and logs in a nice web interface.  Now that parse is open source, you have to install the parse-dashboard project and configure it separately if you want a nice GUI.

 

Install parse dashboard.

 

npm install -g parse-dashboard

Create upstart for it with 

parse-dashboard –appId yourAppId –masterKey yourMasterKey –serverURL “https://example.com/parse” –appName optionalName

kill timeout 300 # wait 300s between SIGTERM and SIGKILL.

start on runlevel [2345]

stop on runlevel [06]

script

  cd /opt/parse-server-example

  #exec npm start >> /opt/parse.log 2>&1

   exec parse-dashboard –config /path/to/config.json

end script

 

You can also start the dashboard from the command line with a config file. To do this, create a new file called parse-dashboard-config.json inside your local Parse Dashboard directory hierarchy. The file should match the following format:

{
  “apps”: [
    {
      “serverURL”: “https://extenarldomainwithcert.com/parse”,
      “appId”: “myAppId”,
      “masterKey”: “myMasterKey”,
      “appName”: “MyApp”
    }
  ]
}

 

You need to issue a cert for your dashboard domain if you want it to be accessible from the web.  The dashboard won’t allow you to login without one.

 So use letsencrypt to issue a cert for it.

 

Install the certbot here https://certbot.eff.org/

 

Make it executable and run it with the nginx flag.  Follow the prompts and you’ll be able to issue a cert for your chosen domain.

 

One catch with certbot, it will try and verify that the domain actually exists.  It does this by just wgetting the domains index.html I suppose, so when you run certbot, make sure you have your DNS pointed to your server, and have a simple little index.html being hosted by nginx so that it can validate you.  

 

Chmod +x cert-autobot

./cert-autobot  –nginx 

 

Then configure nginx 

To do a proxy_pass with the proper cert

Once you have a valid certificate, it’s time to configure nginx to pass dashboard traffic from the web properly to your dashboard and to parse.

 

If you are using javascript sdk or the rest api to talk to parse/ you’ll need to either change the config in index.js  from /parse to /parse/1/ for the rest conformity.

Or you can do a simple rewwrite in nginx.

 

Written by : Ethan Drower

Subscribe To My Newsletter

BE NOTIFIED ABOUT BOOK SIGNING TOUR DATES

Thank you for your message. It has been sent.
There was an error trying to send your message. Please try again later.

Donec fringilla nunc eu turpis dignissim, at euismod sapien tincidunt.

Leave A Comment