How to Set up a Deployd Server in Your DigitalOceans Droplet

To ones haven’t heard about Deployd before, it’s an open source BaaS solution and as in their motto: the simplest way to build an api.

If what you need is a simple API and you are going to use it basically for CRUD operations (it’s likely to do so in most of the cases) Deployd is the perfect fit for you.

Check it out now if you haven’t already: http://deployd.com/


Let’s get started!

At this point, I assume you have a DigitalOceans droplet with Ubuntu up and running. If you don’t, please don’t panic. Creating a virtual server and setting it up in DigitalOcean is smooth as an android’s bottom and you can always read through their guides: https://www.digitalocean.com/community/tutorials/how-to-create-your-first-digitalocean-droplet-virtual-server

Now connect to your server with ssh and follow these steps to install deployd in less than 5 minutes.

1. Set up MongoDB

Deployd uses mongodb to store your collections. So if you want to use a Deployd server you should install mongodb.

$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
$ echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org

Once you installed mongodb now check the port it is listening and note that somewhere. We’ll need it a few steps after.

$ sudo netstat -ntap

Find the line with mongod. In my case, it is 27017. (I don’t know, maybe it is like so in default)

Create a mongodb db and user. Our deployd production script will use this db and user to store your data.

$ mongo
> use deployd
> db.createUser({user:"deployd", pwd:"your_password", roles:["readWrite", "dbAdmin"]})

Again, don’t forget the name of this db (deployd), username (deployd) and password (your_password).

We’ll use them when we set up our deployd script.

You are ready to go on installing deployd (and some nodejs goodies).

2. Install Deployd

Deployd runs on nodejs. So, we start by installing node package manager and its dependencies. (Say yes when it asks for some additional library downloads)

$ sudo apt-get install npm

After it’s completed, install deployd globally.

$ sudo npm install deployd -g

And install forever. This awesome tool makes a nodejs script a daemon. This means whenever your script dies, forever starts it again.

$ sudo npm install forever -g

I think there have happened some curious things about the binary alias of nodejs. So we need to create a symlink and fix the problems before they occur. (You can always comment if you know the reason why there are two aliases of nodejs in use, or maybe, I totally get it wrong.)

$ ln -s /usr/bin/nodejs /usr/bin/node

Now, as these things all set, we can start creating our deployd app.

3. Create Your Deployd Application and Production Script.

I suggest finding a convenient place to your app. /home/deployd/ may be a good place. Go to that directory and start creating your dpd app.

$ dpd create app-name
$ cd app-name

Ehem, link deployd here, so in the script, we can easily use it.

$ npm link deployd

Create a production script inside your apps directory:

$ nano production.js

And paste this code inside:

Don’t forget to replace port, name, username and password with the values you noted down in steps 1 and 2. (In my case they are deployd, deployd, your_password)

Also, if you want you can change env to development instead of production to make easier to display your dashboard. Otherwise, it’ll keep asking dpd-key and make it hard to access the dashboard while you are developing.

PS: Don’t forget to change env to production after you are done with developing, because if it is in development everyone who knows the link can access to your dashboard. We don’t want that to happen, do we?

If you saved your production.js we can now try to run it and see if it works:

$ forever start production.js

You can check if it’s still up with this command:

$ forever list

If you see your script running, you should be able to go to your dashboard and make changes. Go to http://YOUR_IP_ADDRESS:5000/dashboard and try to create properties, add data, etc.

If you can save data rows successfully, well done! You are ready to go with the final step:

4. Making Your Script Auto Start at Boot

Forever is a handy tool and works like a charm. But, what if your droplet reboots? Will it automatically forever run production.js? No.

However, it’s easy to set up a cron which runs at boot to trigger your forever running daemon.

Start by creating a shell script and put that script a nice place. Maybe /home directory.

$ cd /home
$ touch forever_start.sh
$ chmod +x forever_start.sh
$ nano forever_start.sh

Paste this magic lines inside and save it. (Again, don’t forget to replace the app-name and paths if you need to)

#!/bin/bash
/usr/local/bin/forever --workingDir /home/deployd/app-name start /home/deployd/app-name/production.js

Some background info:

If you haven’t written this --workingDir /home/deployd/app-name parameter, you would be in trouble. I spent several hours trying to run forever from a shell script dealing with working directories and stuff. It keeps changing the current working directory, ending up with bunch of errors from nodejs.

Now you can add this little magical shell script inside your cron.

However, you should switch to the root user before adding cron entries. Because crontab -e lets you add cron entries by your current user, so it can run the script with that user’s permissions. forever will not be able to run your deployd app without root permissions.

Run this command to edit your crontab:

$ crontab -e

And append this line to end of the file:

@reboot /home/forever_start.sh

If these all set, your deployd app should start when you reboot your droplet.

To check if it’s set up correctly you can always type command:

$ reboot

And go to your dashboard after reboot.

That’s it. Hope you set up Deployd to your Digital Ocean droplet without any hassle. If you face any problems don’t hesitate to reach out to me via Twitter.


Don’t have a DigitalOcean account? Sign up via this link to give me some free droplet months :)

Thanks to koksal who tried to follow this guide and gave useful feedback on it.

If you’ve liked this article, click recommend to encourage me to keep writing on Deployd :)

Like what you read? Give Ahmet Safa Orhan a round of applause.

From a quick cheer to a standing ovation, clap to show how much you enjoyed this story.