MEAN hosting with Digital Ocean

Create a Digital Ocean account — don’t create a new account with the same credit card (you will get investigated for at least 6 hours, and it’s not worth it).

Create a new droplet (server)

  • Choose a droplet name you can associate with your product.
  • Choose applications MEAN on 14.04
  • Click on Create Droplet

Clone your repo

Ssh to your new droplet with the password you received on your email

$ ssh [email protected]_ADDRESS
$ cd ~/
$ mkdir www
$ cd www
$ git clone YOUR_GITHUB_URL
// cd to your new directory
$ npm install OR npm install --production
$ [sudo] npm install forever -g
$ [sudo] forever start server.js

Good try but this won’t work unless you change some of you code. The default port your browser will try to access is: 80. You are probably using something like port 3000. So quick fix is to change your server port to port 80.

A better option is to determine if you are on production or development mode and adjust the port depending on your environment.

If you don’t have a Node Env variable for dev, follow this: http://stackoverflow.com/questions/22312671/node-js-setting-environment-variables

Here is how this would look:

If setting up your node environment is causing your problems, you can also add a key to a file non-tracked by Github — could be something like keys.js. On your computer you can then define env as DEVELOPMENT and on your droplet, set that env as PRODUCTION. Then, in your server, after importing that file — something like:

var keys = require('./config/keys.js)

You can choose a port number with a simple if statement:

Alright! Let’s push that change to github, then ssh to server on your project directory, git pull then:

$ forever stopall
$ forever start server.js
OR
$ forever restartall

You are done. Going to your IP address will ping your server, and the rest is magic.

Now, a couple of things:

  • Buy a domain
  • Point DNS records to Digital Ocean:
How To Set Up a Host Name with DigitalOcean | DigitalOcean
DigitalOcean’s DNS allows you to easily set up your hostname from the DigitalOcean control panel. Before you get…www.digitalocean.com

There are some changes you probably want to make to your droplet (mostly for security reasons):

Initial Server Setup with Ubuntu 14.04 | DigitalOcean
When you start a new server, there are a few steps that you should take every time to add some basic security and give…www.digitalocean.com