The MERN Stack Explained

Kevin Michael Johnson
3 min readMay 17, 2021

Hello everyone and welcome back! Today we are going to be talking about the MERN stack, and going over each component of the stack and what part it plays in helping create amazing projects.

First, let’s talk about what MERN is and what does MERN stands for. To begin, the M stands for MongoDB and that is a database solution. The E stands for Express.js, I’ll come back to what this is in a second. The R stands for React GS, and this is a browser-side javascript library that helps you build amazing user interfaces. Finally, the N stands for Node.js. which is a server-side JavaScript runtime, an environment where JavaScript code can be executed outside of the browser. Now Express.js is a framework for Node.js which in the end makes building Node.js applications much easier! Basically, Express.js has powerful models for URL routing (matching an incoming URL with a server function) and handling HTTP requests and responses.

MERN Architecture

The MERN architecture allows you to easily construct a 3-tier architecture (frontend, backend, database) entirely using JavaScript and JSON.

The Top Tier

At the top of the MERN stack is where React.js comes into play. This JavaScript framework allows us to create dynamic client-side applications in HTML. React lets you build up complex interfaces through simple Components, connect them to data on your backend server, and finally render them as HTML.

React relies on handling stateful, data-driven interfaces with minimal code without jeopardizing the ability to create a modern web framework.

Middle Tier

The next level down is the Express.js server-side framework, running inside a Node.js server. Express.js is a “fast, unopinionated, minimalist web framework for Node.js,” and that is exactly what it gives you! Express.js has powerful models for URL routing (matching an incoming URL with a server function), and handling HTTP requests and responses. By making XML HTTP Requests, or GETs and POSTs from your React.js front-end, you can connect to Express.js functions that power your application. Those functions in turn use MongoDB’s Node.js drivers, either via callbacks for using Promises, to access and update data in your MongoDB database.

Bottom Tier

If your application stores any data (user profiles, content, comments, uploads, events, etc.), then you’re going to want a database that’s just as easy to work with as React, Express, and Node.

That’s where MongoDB comes in: JSON documents created in your React.js front end can be sent to the Express.js server, where they can be processed and (assuming they’re valid) stored directly in MongoDB for later retrieval.

Why choose the MERN Stack?

The MERN stack’s main advantage in web development is that each line of code is written in JavaScript, which is a universal programming language since it is extremely important and often used for both server-side and client-side code. By using a single programming language, the MERN stack takes away the need for switching back and forth and makes things much easier during the entire development process. This can give web developers the ability to create efficient web applications with far less effort.

The combination of these technologies also means that JSON data flows from front to back, making it fast to build on and reasonably simple to debug. So finally the question isn’t why to use MERN, but maybe why not! Happy Coding everyone!

--

--