← Back

Why I Like the MEAN Stack

The MEAN stack offers a coherent foundation for building modern, testable web applications. This article explores its benefits, challenges, and career opportunities.

MEAN StackNode.js

I admit I’ve always been very interested in web development. In fact, I first started exploring it on my own back in 2006, eventually falling in love with the wonderful Drupal, which I used to start a startup (which, like so many, never quite took off). Although my primary responsibility at the company I work for is leading a development team, one of my mantras is to never lose touch with the plumbing and low-level concepts of software development. How can you manage a software project without knowing its building blocks inside and out? Of course you can manage one, but the risk of making bad decisions, running into overruns, and so on will be much higher. That’s why I’ve always kept a close eye on web trends and initiatives, some of which have lasted and others fallen out of use, even though most of my work has been on heavyweight applications built primarily with .NET technologies.

When we say the economy is going digital, we don’t always grasp the enormous implications this has for professional software developers. It means that massive financial resources are being poured into launching business projects and ventures on the Internet, and therefore the demand for good professionals with demonstrable expertise will keep growing.

The anecdotal websites of the 1990s, little more than advertising brochures, are long gone. For years now, we’ve been talking about a real industry that’s changing how we relate to one another and how technology transforms social habits, as with the concept of the sharing economy.

There’s a lot written about MEAN, so I’ll focus on the real reasons why I believe developers who know this stack well won’t be short of work in the coming years.

Briefly, what is the MEAN stack? It’s a set of related technologies that provides everything you need to build a modern, scalable, testable, and—above all—maintainable web application (though that last part depends on good practices). MEAN stands for:

  • MongoDB, a non-relational database. The stack absolutely doesn’t require MongoDB; in fact, I’m currently involved in a project using MySQL + _EAN.
  • Express, an extraordinarily simple and powerful middleware for building web applications. You can learn it in an afternoon, seriously…
  • AngularJS, an extraordinarily powerful declarative approach to building user interfaces. It lets you implement MVC (or MVVC, depending on your preference) on the web client, decoupling presentation logic, business logic, views, and models. Here’s what’s important: because they’re decoupled, you can write tests for them! Also, AngularJS is a Google project.
  • NodeJS, a server framework with an incredible and expanding universe of modules that lets you write server applications in JavaScript using an event-driven programming model. NodeJS can be used as a framework in many scenarios. One of them (by no means the only one, though it’s often confused as such) is web application development.

Put all the pieces together and you get a very mature, coherent stack for building modern, scalable, and testable web applications. Of the building blocks at its heart, the most significant to me are Express’s middleware through the Connect module; AngularJS directives and its implementation of MVC, all of which can be tested with Mocha and Karma; and, above all, NodeJS’s event-driven development model, which lets you forget about concurrency and synchronization problems between asynchronous operations.

Several years ago, whenever I returned to a web project, I was struck by a few things I really didn’t like:

  • The direct, horrible manipulation of the DOM (this was quite a few years ago), with all the cross-browser problems.
  • Coming from a heavyweight framework like .NET, where C# brought consistency to a complete solution (front-end, back-end, and access to data repositories or services), I found it frustrating to use certain client-side technologies and other server-side technologies (JavaScript, CSS, and HTML on the client, and PHP, for example, on the server). This made maintaining a single project enormously expensive.

Over time, better standardization options emerged, along with wonderful libraries like jQuery and its widgets, Modernizr, and CSS preprocessors such as Less, Sass, and Stylus. They freed developers from fundamental problems and let us write code that was more readable, faster to produce, and easier to maintain. Even so, there was still a clear divide between front-end web development and server-side back-end development—and most web applications are still built that way.

Then, a few years ago, I read an article about an emerging project called NodeJS that left me puzzled. I knew something important had been achieved, though I couldn’t say exactly why at the time. Eventually the pieces fell into place, though I admit that the day I first encountered NodeJS I had an epiphany… even though I still didn’t know what it could be used for.

There are no good or bad technologies (the endless .NET-versus-Java and Oracle-versus-SQL Server debates are almost childish, really…). It all depends on the nature of the project and the technical competence of the person implementing it (especially the latter): a developer who specializes in spaghetti software won’t use any framework well, and using a wonderful database engine without knowing it well enough will ruin an application with poorly written queries, and so on. We sometimes forget that every technology or technology stack has pros and cons, and that most of the time we dismiss the ones we don’t like simply because we don’t understand them.

For some time now, I believe the MEAN stack has reached enough maturity, market traction, and community support to be taken very, very seriously. It’s an emerging set of technologies that will be talked about—and used—a great deal in the coming years. I have no doubt about that.

So what does this stack offer? In my opinion, these are the main points:

  • It lets you build a web application from end to end using JavaScript as the only language, although, naturally, the libraries used on the front-end differ from those used on the back-end with NodeJS.
  • Used well, AngularJS frees you from directly manipulating the browser DOM. It lets you declaratively write much of the user interface functionality and, most importantly, decouples client-side logic using the model-view-controller pattern, making it possible to write tests.
  • The stack makes it easy to build SPAs (single-page applications), where the web client handles much of the application logic and the server provides the API that supports it. This avoids repeated full HTTP requests for the entire HTML document and its software artifacts.
  • You get a high degree of control over lower-level concerns (cookie management, headers, routing, and so on), while they remain abstracted enough to be trivial to use.
  • Elegant testing frameworks are available for both the front-end and the back-end.
  • Application deployment is straightforward.
  • When you follow good practices, it’s cross-platform.
  • …and much, much more.

Of course, it has drawbacks, but as with any other stack, you need to know whether it’s suitable for the nature of the application you want to build. We can’t call the learning curve quick: AngularJS, for example, makes you think about solving the web-client side differently, and NodeJS’s asynchronous model also requires a different mental approach to the server side.

Right now there’s a huge shortage of professional developers building MEAN or similar applications, so this will be a rapidly growing market—and opportunity—in the coming years, both for developers and for companies offering MEAN-based solutions.

There’s also a lack of good, high-quality literature on the subject in Spanish (in English, naturally, there are plenty of excellent books). Yes, yes, I know most software developers are used to reading in English, though I have serious doubts about that claim, and I’ve got a post in the works about it.

Perhaps the lack of high-quality Spanish-language literature on MEAN will soon be remedied…