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.
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:
And we’ll need to install Git, as it will be needed later.
Before we can install Node we’ll need some packages brought in:
Then we’ll add a new repo:
And update again.
Then we should update NPM:
And once that’s done we’ll install Bower and Grunt:
MongoDB will be the backend for the website. This is a relatively quick install, but must be done before the MEAN stack is installed.
First we need to import the public key:
Then we need to create a list file for Mongo:
Then run another update:
And then we can install MongoDB:
Now, check to see if MongoDB has started:
You should see this message:
And your MongoDB is up and running!
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)
and run it:
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:
Now start it up:
and you’ve got a full time server running.
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.