What is the MEAN stack?

This post is 4 years old. (Or older!) Code samples may not work, screenshots may be missing and links could be broken. Although some of the content may be relevant please take it with a pinch of salt.

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.

Update

I got some great feedback from the community and I do appreciate that. I'd like to make it clear that the same way the LAMP stack can change to a WAMP stack, or PHP can change to Python, the MEAN stack can change to hold different languages as well. You can use EmberJS or BackboneJS instead of AngularJS for example. However, the concept is pretty much the same - you are still using JavaScript as the main language spanning across your backend and frontend services. Some people may also prefer CouchDB instead of MongoDB.

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: TechnologyLAMPMEANServerLinux: I think this is pretty straight forward. The basic of the LAMP stack is that it's running on a Linux distribution.NodeJS: this is a bit tricky. NodeJS is the server that runs your application, however NodeJS has to run on Linux as well. NodeJS is an event-driven I/O server-side JavaScript environment based on Google's V8 engine.WebServerApache: 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.DatabaseMySQL: 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.LanguagePerl/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?

Because everything is based on JavaScript / JSON.

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 (soccer) players.

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.