Pros and Cons of the MEAN Stack
A favourite of mine, the MEAN stack is a hugely popular combination of technologies in the web development sphere. Of course, you’ll hear from people who love it and sing it’s praises, and those who think it should die.
To help you make up your own mind about the MEAN stack, I’ll share it’s pros and cons here. These are the reasons I learned it, as well as some extra info I picked up along the way. I’ll list the pros and cons of each technology.
Node.js
One of the more prominent server side technologies you’ll hear of is Node. One of the reasons behind its fame is the fact that it runs JavaScript, bringing the most prominent front-end language behind the scenes.
Pros:
- It’s Javascript – This cuts the learning curve dramatically for those of us who are already knowledgable in the front-end.
- It’s Popular – I don’t condone blindly doing what everyone else does, but going with the crowd sometimes has perks. The huge popularity of Node means there’s a lot of information circulating online to help you learn and debug your code.
- NPM – Node Package Manager is a HUGE repository of open-source code libraries for you to use, helping you with everything from JSON parsing to automated emails. Most of the packages have great documentation to help you figure them out.
- Asynchronous – Node runs asynchronously, just like a browser. What this means is that it basically multi-tasks with your code. If you make a database query, this takes time, you won’t receive the data instantly. Node keeps track of that process in the background while it moves on to the next task in the code. This means it can handle many requests at once without them blocking each other.
Cons:
- Doesn’t support the use of multiple cores – Node will only use one CPU. Avoid CPU intensive tasks. It’s better suited for I/O situations.
- Callbacks – The asynchronous nature of Node comes at a price. In order to use the information returned from a time consuming process, like our database query example, you need to use a callback to specify the code you want to execute once the process is complete.
I’ll write a blog post explaining callbacks in the near future.
Express
Express is a popular framework for Node. It’s lightweight which means it only abstracts the lowest level tasks, still exposing much of the workflow to the developer. This makes it a great framework with which to learn back-end development. Almost everyone who uses Node uses Express, so documentation is aplenty and there’s a lot of information on Stack Overflow.
MongoDB
The most popular option for data storage with Node is MongoDB. You’ll use a library called Mongoose to interface with the database, but MongoDB is the software behind it all.
Pros:
- Non-relational – Non-relational databases are much more flexible than relational ones. There aren’t strict rules on keeping records identical, so you can store more information and more sketchy relationships without breaking the database. Keep in mind that doing so can make working with the data more complex.
- Intuitive – Mongoose uses quite intuitive methods and syntax so it’s not too much of a learning curve. Even if you have no experience with databases, with a little bit of a walk through you can figure it out pretty fast.
- Easy to scale – When your app goes into production and becomes world famous, you’re going to need a lot of space and performance. Fortunately you used MongoDB, and scaling up performance is as simple as connecting more servers to the system.
Cons:
- Higher Data size – The non-relational nature of MongoDB means you have a little more data overhead to keep things organised. You need to store both the key and value for each property of each record. In SQL everything in the table must be identically typed meaning you can dispense with the keys, reducing the data overhead significantly.
- Less querying flexibility – Querying the database can feel a little inflexible at times since it doesn’t support some of the powerful SQL commands like JOIN. However, if you spend a little more time planning the data relationship structure, you can work around this most of the time.
- Fast evolving, less up to date documentation – MongoDB is still going through rapid development. Sometimes you’ll have a hard time finding documentation for a specific feature you want to leverage in your code.
That’s the back-end technology of the MEAN stack. As you can see it’s lightweight, flexible and rather easy to learn. The downside is some performance concerns in certain circumstances.
Now we move on to the front-end favourite for many apps working with these back-end technologies.
Angular
I’m sure you’ve heard of Angular by now. Everyone’s talking about this revolutionary framework, for good reason.
Pros:
- Brings the MVC (Model-View-Controller) framework client-side, enabling SPA functionality – Angular allows you to handle a lot of the controller logic in the client browser, so you can build single page applications (SPAs). Your Angular code will change the view to reflect the model, and take user input to affect the model using AJAX calls to your back-end without ever having to load a new page.
- Two-way data binding – This is one of Angular’s signature moves. It directly connects a variable in both the view and the model, so any changes made on either side are reflected in the other.
- Directives and Components – Directives and Components are Angulars other specialty, allowing you to write code templates that can be implemented and reused in multiple places in your app.
- Great documentation – Google manages the development of Angular, and I found their documentation to be superb, they even have tutorials. It’s popularity also means you’ll find plenty of extra information on Stack Overflow etc.
Cons:
- Heavyweight framework – Angular uses a huge library of code, so it can really affect the load time of the page. Take this into consideration when deciding to use Angular. It’s best suited for moderately complex SPAs. For basic DOM manipulation, jQuery may be a better choice.
- Complex scoping – It’s a very opinionated framework, which means you’ll have to learn the Angular way of handling scope in your code. By default, components don’t have access to anything outside of its own scope, but you can easily change that if you know how.
- Can be difficult to learn – I found Angular difficult to learn without a pretty comprehensive online course. It’s complex, unique and opinionated so the learning curve is pretty steep before you can really take advantage of the real benefits.
Thanks for reading my article, I know it’s quite long but hopefully it’s helped you make a decision on whether you should use, or learn the MEAN stack. I find it to be a pretty powerful combination of technologies, and I’m glad it’s the first one I learned.