- 15 November, 2018 22:00
Most anyone who has developed web applications knows the acronym LAMP, which is used to describe web stacks made with Linux, Apache (web server), MySQL (database server), and PHP, Perl, or Python (programming language).
This consistency stands in contrast to the hodgepodge of LAMP, the longtime staple of web application developers. Like MEAN, LAMP is an acronym for the components used in the stack—Linux, the Apache HTTP server, MySQL, and either PHP, Perl, or Python. Each piece of the stack has little in common with any other piece.
This isn’t to say the LAMP stack is inferior. It’s still widely used, and each element in the stack still benefits from an active development community. But the conceptual consistency that MEAN provides is a boon. If you use the same language, and many of the same language concepts, at all levels of the stack, it becomes easier for a developer to master the whole stack at once.
Most MEAN stacks feature all four of the components—the database, the front-end, the back-end, and the execution engine. This doesn’t mean the stack consists of only these elements, but they form the core.
Like other NoSQL database systems, MongoDB uses a schema-less design. Data is stored and retrieved as JSON-formatted documents, which can have any number of nested fields. This flexibility makes MongoDB well-suited to rapid application development when dealing with fast-changing requirements.
Using MongoDB comes with a number of caveats. For one, it has a reputation for being insecure by default. If you deploy it in a production environment, you must take steps to secure it. And for developers coming from relational databases, or even other NoSQL systems, you’ll need to spend some time getting to know MongoDB and how it works. InfoWorld’s Martin Heller dove deep into MongoDB 4 in InfoWorld’s review, where he talks about MongoDB internals, queries, and drawbacks.
Express is arguably the most widely used web application framework for Node.js. Express provides only a small set of essential features—it’s essentially a minimal, programmable web server—but can be extended by way of plug-ins. This no-frills design helps keep Express lightweight and performant.
Nothing says a MEAN app has to be served directly to users via Express, although that’s certainly a common scenario. An alternative architecture is to deploy another web server, like Nginx or Apache, in front of Express as a reverse proxy. This allows for functions like load balancing to be offloaded to a separate resource.
Because Express is deliberately minimal, it doesn’t have much conceptual overhead associated with it. The tutorials at Expressjs.com can take you from a quick overview of the basics to connecting databases and beyond.
For a deep dive into Angular, InfoWorld’s Martin Heller has you covered. In his Angular tutorial he’ll walk you through the creation of a modern, Angular web app.
Node.js takes a different approach to serving web requests from traditional web servers. In the traditional approach, the server spawns a new thread of execution or even forks a new process to handle the request. Spawning threads is more efficient than forking processes, but both involve a good deal of overhead. A large number of threads can cause a heavily loaded system to spend precious cycles on thread scheduling and context switching, adding latency and imposing limits on scalability and throughput.
Node’s approach requires less memory to handle more connections than most competitive architectures that scale with threads—including Apache, ASP.Net, Ruby on Rails, and Java application servers. Thus Node has become an extremely popular choice for building web servers, REST APIs, and real-time applications like chat apps and games. If there is one component that defines the MEAN stack, it’s Node.js.
MEAN stack companions
There’s nothing that says a MEAN stack must consist of only MongoDB, Express, Angular, and Node.js. The MEAN stack can include other pieces that complement or extend these four components.
For example, caching systems like Redis or Memcached could be used within Express to speed up responses to requests. Or the React framework could be used as an alternative or a complement to Angular. The acronym “MERN” is sometimes used to describe MEAN stacks that use React in place of Angular.