Mostly Coherent Ramblings of a Silicon Forest Software Developer

How to Set Up the MEAN Stack on Digital Ocean

Author: Jeremy Morgan

Oct 26th, 2014

If you haven’t heard of the MEAN stack, it’s a combination of technologies for serving up fast websites, using a set of technologies paired very well together. They consist of MongoDB, Express.JS, Angular.JS, and Node.JS. For more information check out MeanJS website for more details.

This is not to be confused with Mean.IO. This is also a MEAN stack, but the original creator forked it and started MeanJS instead. I find it to be less error prone and a bit more organized.

How to set up a MEAN stack on Digital Ocean.

Digital Ocean is one of the greatest services for a developer. You can spin up virtualized Linux servers for as little as $5 a month, and it’s a great cheap way to host your projects.

I know what some of you are thinking, “why not just press the MEAN app button on the console?”. This is a great way to set up a MEAN stack, but I am a firm believer in doing stuff like this manually. It’s important to know what you’re installing and how to do it, rather than rely on GUI tools for everything. You don’t really learn unless you do it.

That being said this article isn’t really specific to Digital Ocean, you can follow these steps on any Ubuntu machine. Digital Ocean just happens to be a good platform to try it on.

Get Started

To get started we’re going to create a droplet. For this tutorial I created an Ubuntu 14.04 x64 version.

The first thing you’ll want to do once you log in, is update it:

1

sudo apt-get update

And we’ll need to install Git, as it will be needed later.

1

sudo apt-get install git

Install Node.JS

Before we can install Node we’ll need some packages brought in:

1

sudo apt-get install python-software-properties python g++ make

Then we’ll add a new repo:

1

sudo add-apt-repository ppa:chris-lea/node.js

And update again.

1

sudo apt-get update

1

sudo apt-get install nodejs

Then we should update NPM:

1

npm install -g npm

And once that’s done we’ll install Bower and Grunt:

12

sudo npm i -g bower
sudo npm install -g grunt-cli

Install MongoDB

MongoDB will be the backend for the website. This is a relatively quick install, but must be done before the MEAN stack is installed.

Install MEAN.JS stack

You’re almost done! This part is quick and easy. Just clone the latest repo into a folder (I used meanjs)

1

git clone https://github.com/meanjs/mean.git meanjs

install it:

1

sudo npm install

and run it:

1

grunt

You’re done! You should see the following screen:

And just like that you’re ready to go.

If you want to run it as a full time server

When you run Grunt it starts your server, but as soon as you exit SSH it drops. Also NodeJS is a single threaded application so a single failure can bring down the service. This is why we use forever to run the server:

1

npm install forever

Now start it up:

1

forever start server.js

and you’ve got a full time server running.

Conclusion

I hope this helps illustrated the steps for getting a MEAN stack set up. This is just the beginning, in future tutorials we’ll build some stuff.

This stack is pretty awesome, and really important. I can definitely see this replacing PHP as a go-to quick web development technology for open source platforms. It’s advancing rapidly, offers incredible performance and reduced development time.