Over the past few weeks I talked to a lot of people and the question I got asked the most was 'What is the MEAN stack?' That's a very legitimate question and in this post I will try to describe my understanding of the MEAN stack and hopefully provide you with a clear understanding on what this new acronym is and how you can set it up on your own.
MEAN is an abbreviation and encompasses some new technologies, namely MongoDB, ExpressJS, AngularJS and NodeJS. The way this stack functions is similar to how the LAMP stack/framework works - let's do a comparison between the two them:
|WebServer||Apache: most people would run their scripts on an Apache server, very commonly used.||ExpressJS: is a node.js web application framework. It helps to create an MVC like application on the server side, allows users to create routes and templates as well. (It comes with a support for a great number of multiple templating languages as well, the most common one being Jade.|
|Database||MySQL: the obvious choice for most people, it's a great RDBMS, I have been using it since forever. Some people prefer to use PostgreSQL as well, there are pros and cons for against for both - those are outside the scope of this article.||MongoDB: A superb No-SQL database. I wrote a lot about how/where/why to use it, have a look at some of my previous articles.|
|Language||Perl/PHP/Python: In the LAMP stack these are the most commonly used programming languages.||AngularJS: Now this is tricky to compare with the other languages. AngularJS is framework to create one-page dynamic apps and it runs on the client side whereas the other languages in the traditional LAMP stack would run on the backend. Think about AngularJS as a great and dynamic extension to HTML.|
So after all this being said, why would someone want to use the MEAN stack?
Having one, standalone language makes development a lot easier. MongoDB stores JSON like objects (actually, they are BSON - Binary JSON objects), which can be served easily from NodeJS and ExpressJS, either with the native MongoDB driver or with third party drivers, such as Mongoose. Further to this, it's incredibly straight-forward to pass a JSON object to AngularJS and store it as a variable in the
$scope for example. This also means that there is are differences between the objects that are stored & returned by the backend and the objects used by the frontend. You have a very nice, self-contained storage & display mechanism throughout your application, all using the same data, and most importantly, the format of your data is the same.
First, I recommend that you setup all these tools on your own - you install nodeJS, ExpressJS and MongoDB on your development machine and play around with them a bit to get a feel how they function and how they interact. Once you get comfortable you can actually go and clone a GitHub repo - the people behind Linnovate put together a great starter pack for the MEAN stack.
If you believe that this is too advanced for you, you may want to try this great MEAN tutorial by Thinkster. I am at the moment thinking about buying the licence from them and create a more 'European' friendly version - instead of using NFL players, I'd like to have football (
There's also a great tutorial on how to setup a complete MEAN stack on an Amazon EC2 environment that I have helped my friend with - and he's done an excellent work documenting every step. The configuration that he explains takes an additional step on top of what you'd normally do in order to have the MEAN stack up and running. I personally don't like to let nodeJS run on port 80 so I usually setup a reverse proxy. My choice fell to Ngnix, as it's light, reliable and perfectly fits the scenario. It basically listens on port 80 and redirects all calls to port 3000, on which nodeJS & ExpressJS are running (by default). Check the tutorial out - with the exact steps on how to setup MEAN in the cloud using an Amazon EC2 instances - including ssh key pairing, MongoDB installation and ngnix configuration.
One word of a warning though: the MEAN stack is very addictive, use it at your own risk. Have fun.