https://www.digitalocean.com/ – digitalocean site
https://cloud.docker.com/ – create account to get $20 off for Digitalocean (have 2-3 images for this)
https://github.com/Unitech/pm2 – pm2 - Process Manager for NodeJS

Digital Ocean is a cloud computing service that allows you to create and access servers with ease. You choose the tier of storage/performance you want, DO’s terminology is a ‘Droplet’. Once you create a Droplet, it will give you an IP address, and with this you can ssh into the server.

NOTE: before we signup for DO, I’m going to show you how to get $20 credit. We have to signup for docker(specifically docker.cloud) and in the dashboard it offer you the $20 credit for DO.


Signup/signin into http://cloud.docker.com h

Click ‘Cloud Settings’ h

Click ‘Digital Ocean – $20 Code’ h




Creating a Digital Ocean account

Visit https://www.digitalocean.com/ and create an account. After clicking ‘Signup’ enter in your $20 credit code and enter in your Credit Card info: h

This should bring you to your ‘Droplets’ page. Click ‘New Droplet’. Fill in the following:

For this very simple demo we are going to use ‘One-click App’ and then select ‘Node X.XX on Ubuntu XX.XX’ h

Going to choose the $5 a month plan (you can cancel at any time) h

In your terminal $ pbcopy < ~/.ssh/id_rsa.pub and paste the generate SSH key h

Copy the IP address of your server h




Creating a simple Express js app

Now in your terminal, connect remotely to the server using SSH with this command:
$ ssh root@<SERVER_IP_HERE>

We are now in the file system for our server. There is alot of config you can do here, such as security, but I’m going to just create a simple express app and then try to connect to it over the web.

Lets create a /apps directory and create a new directory inside of it call ‘apps/test_do’

$ mkdir -p /apps/test_do
$ touch server.js && npm init press enter until it generates a package.json file for you
$ npm i --save express

THE EXPRESS FILE to edit files from the terminal, I’m going to use NANO, $ nano <FILENAME>


// server.js

const app = require('express')()
const PORT = 3030

app.get('/', (req, res) => {
  res.send('hello there world! \n')
})

app.listen(PORT, () => console.log(`server listening on port ${PORT}`))

Now run $ node server.js. You should now be able to access the simple app at http://<YOUR_SERVER_IP>:3030 and be served ‘hello there world!’ This works fine, but what if we want the app to be running at all times, even if we don’t have it currently running in a terminal window? We can use pm2 (node process manager for this).

pm2

https://github.com/Unitech/pm2

install pm2 with $ npm i -g pm2. Check out pm2’s documentation. To get our app to run in the background, we can run $ pm2 start server.js

$ pm2 list shows all current running processes.

Now we can exit our ssh session, and visit http://<YOUR_SERVER_IP>:3030 and our app will still be running (it’s running remotely on our server)