It's High Time to Say Goodbye to the LAMP Stack and Hi to the MEAN Stack

DZone 's Guide to

It's High Time to Say Goodbye to the LAMP Stack and Hi to the MEAN Stack

Looking for a new suite of technologies for your next web development project? Read on for an overview of the benefits of the MEAN stack for full-stack web development.

· Web Dev Zone ·
Free Resource

MongoDB is a NoSQL database that provides flexible data storage layers, and Node.js keeps your server running continuously. It harnesses the potential for a faster computer network. Express.js standardizes web application development and Angular.js allows interactive gestures on web applications. Together, they form the MEAN stack.

Developers, who realized the LAMP stack (Linux, Apache, MySQL, and PHP) is not flexible enough to serve their purposes, are gradually making a move towards the MEAN stack. And it's high time you should too. There are many reasons to do so.

MEAN Stack LAMP Stack
Operating System Cross-platform Linux OS only
Database MongoDB, a ‘non-relational’ database MySQL, a ‘relational’ database
Programming Language(s) Front-end—JavaScript backend—PHP JavaScript, back- and front-end
Structure Slower and limited due to its blocking structure. faster & scalable due to its non-blocking structure.
Technologies MongoDB, Express.js, AngularJS, Node.js Linux, Apache, MySQL, PHP
Mainstream Backers Google, IBM, Samsung Oracle, Zend, Linux Foundation

The MEAN Stack

Developers looking to host maximum user engagement on their web app choose the most feasible technologies and frameworks. There is a long list of technologies and the MEAN stack is a recipe to create modern web applications. Introduced in 2014, MEAN has transformed the way the web development process goes. As mentioned above, the four components in the MEAN Stack are:

  • MongoDB, document database - used by your backend application to store its data as JSON (JavaScript Object Notation) documents.

  • Express.js, a backend web application framework running on top of Node.js.

  • AngularJS, a front-end web application framework; runs your JavaScript code in the user's browser, allowing your application UI to be dynamic.

  • Node.js, a JavaScript runtime environment - lets you implement your application backend in JavaScript.

The MEAN stack is all about using the same programming language for all the components of backend JavaScript development and front-end development. Access to the database is through MongoDB's idiomatic driver. Drivers facilitate interaction using typical JavaScript concepts such as objects and async execution, using either callback functions or promises. I have inserted an array of three objects in JavaScript:

The Database System: MongoDB

MongoDB has the best of both worlds. It has the fast, scalable key-value stores of NoSQL and the rich functionality of relational databases. Unlike relational databases, MongoDB stores BSON documents inside collections with active schemas.

While relational databases like MySQL store data in specific rows and columns, MongoDB's document data model stores data regardless of its structure and doesn't void existing authentication rules, data access, or indexing functionality. You can actively adjust the schema without interruption.

The Backend Web Framework: Express.js

Express is a web application framework that executes backend application (JavaScript) code. Express is a module Node.js environment and runs under it.

Express handles the allocation of requests to different parts of an application (or to various apps running in the same environment).

Express executes the part of a web app's code that is responsible for business logic and returns an HTML file to be compiled by a web browser. However, Express mostly gives RESTful APIs that the front-end can access with a single line of code.

The Frontend Framework: AngularJS

Angular renders JavaScript code in a web browser's environment to make way for a reactive user interface (UI). Unlike static web forms where you have to fill in the form and hit submit, reactive UI reflects a user's input without refreshing the entire page, but only the essential components.

You implement your web app front-end as a group of components. JavaScript code attached to an HTML template contains hooks to execute and employ the results from your JavaScript functions. Multifaceted application front-ends can be built from many simple or nested components.

Code for Angular applications can compile in the backend server rather than in the front-end browser, or as a native desktop or mobile app.

The Backend Runtime Environment: Node.js

A JavaScript runtime environment to run your backend application with the help of Express, Node.js is based on Google's V8 JavaScript engine, which powers Google Chrome and the open-source Chromium browser. Many of its modules are essential for deploying web applications on the MEAN stack - including HTTP. Third-party modules can be installed with npm.

Node.js is asynchronous and event-driven. That is, an application doesn't poll an acknowledgment to a request. It resumes other tasks in the meantime. Upon completion, a callback request informs the application and it can start other tasks for optimal resource utilization, which enables many parallel operations while scaling applications. MongoDB can work asynchronously too and, thus, works well with Node.js applications.

If you are still not sold on the MEAN stack, we will take you through why you should be using it for your next web development project.

One Language to Rule Them All: JavaScript

Every piece of code in the MEAN stack is JavaScript. On the other hand, in the LAMP stack, the server-side is coded in PHP, the client-side in JavaScript, and queries are sent using MySQL. With MEAN, MongoDB allows you to work with JavaScript - it's the binary version of JSON. In a nutshell, the same language works, on both the client- and server-side.

Cost-Effective While Fast and Scalable

A team of JavaScript developers can code for the server-side and client-side using the MEAN stack. So, no need to hire separate teams for different technologies. The same developer can switch roles between a front-end and backend developer. This will save you a lot of money. For the first time in the history of web development, a full-stack developer needs to know only one language.

Advantages of Node.js

Node.js is a crucial part of the MEAN stack and is a very scalable and robust framework. Node.js is the runtime environment and is compliant with non-blocking input and output. Thus, a new query is handled efficiently. In the LAMP stack, the client had to direct a request for the query to be created. With Node.js, this all happens automatically.

The MongoDB Advantage

MongoDB is the database web developers need while managing huge amounts of data. The whole thing works like OOPs and makes way for easy, effective handling.

Open-Source-Edit the Source, Compile, and Install

The technologies at use in the MEAN stack are all open source. That is, developers get access to the code for each technology and can modify it to meet their individual needs. The technologies don't cost a buck to use and distribute, which means, not only can you use it for personal use but you can install them on your employees' personal workspaces.

Good Community Support

A large community of individual and corporate contributors and sponsors back the technologies in the MEAN stack and the MEAN stack itself. When you are unable to debug a nasty piece of code, there are people there to help.

full-stack development, mean stack, mongodb, node.js, web application development, web dev

Published at DZone with permission of Ubaid Pisuwala , DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}