What makes the MEAN stack magnificent is the one thing most people haven’t noticed. (Originally published on Medium)
The MEAN stack is not opinionated.
The MEAN stack is flexible.
The MEAN stack can be architected in a number of different ways.
This is the strength of the MEAN stack. This is often forgotten or ignored.
Common MEAN stack architecture
The most common architecture centres on an Angular SPA (Single Page Application), using the rest of the stack as an API to provide data services. This is a great and very powerful architecture. If you want a data-driven SPA, then this setup on the MEAN stack will serve you well.
Most frameworks and online tutorials leave it there. This compounds the myth that the MEAN stack is only good for web applications, and even more specifically SPAs. This is not true, and is often used as an argument by developers on other stacks to not move over.
In the early stages of writing Getting MEAN I heard “Node is no good for websites” and “You can’t use the MEAN stack to build normal websites”. Now, what people mean by “normal websites” is another topic for discussion. Regardless, the assertion that you can’t build websites in the MEAN stack also not true. Look a little closer at the tools at your disposal and you’ll see you can use them in different ways.
Matching tools to solutions
Take a look at Express. That’s a web application framework right there. Yes you can use Express to create an API. You can also use Express to consume an API, process data, render a view template and push HTML to the browser. Sometimes there is a better solution to your problem.
SPAs can give a great user experience, but are generally more complex to code. Most coders don’t care about the complexity issue. Complexity provides challenges, and most coders are smart people and most smart people like challenges.
The MEAN stack can be whatever you want it to be.
What can the MEAN stack give you?
You want an SPA? You got it. Build the SPA in Angular, and build a REST API in Node and Express to interact with MongoDB.
You want to deliver HTML directly from the server? You got it. Build your application in Express and use one of the templating engines available. You can still use Node and Express to build an API, or tightly couple your Node/Express application to your database. It’s up to you, depending on your needs.
You want to deliver HTML from the server, but add some interactive Angular components in? You got it. You can have an Express application like above, and have Angular components. You did expose your data through an API didn’t you?
You want a hybrid, delivering a public site directly from the server, with an SPA for private admin? You got it. You can mix and match to your heart’s content with the MEAN stack.
The MEAN stack is flexible. The MEAN stack is not opinionated. The MEAN stack is fully featured. You can do more with the MEAN stack than first meets the eye. Don’t forget it, embrace it, be creative and love it. Create the best solution, and use all of the tools available to you. The future and longevity of the MEAN stack depends on you, so take it out of the pigeon-hole and let it realise its full potential.