---
title: MERN Stack Explained: Roles, Request Flow, Example API
url: https://www.masaischool.com/resources/mern-stack-explained
description: What the MERN stack is: roles of MongoDB, Express, React and Node, how one request flows, a working API you can run, MERN vs MEAN and a free deploy path.
updated: 2026-12-01
publisher: Masai (https://www.masaischool.com)
---

# MERN stack explained: what each part does, with a working API

> **Short answer**
>
> **MERN** is a JavaScript stack: MongoDB stores data, Express and Node.js run the server and API, and React builds the interface in the browser. One language runs across all four. MEAN is the same stack with Angular instead of React. It suits full-stack web apps and portfolio projects.

This page is for students who keep seeing 'MERN developer' on job posts and want to know what the four parts do and how they connect. The code that runs below was executed on Node.js v24.15.0. The Express and Mongoose snippets were proofread but not run, because Express and MongoDB were not installed on the machine used.

Facts about packages and plans were read on 1 December 2026: the npm registry lists Express 5.3.0, React 19.3.1 and Mongoose 9.13.1 as latest. For where MERN sits among other stacks, read [tech stack explained](https://www.masaischool.com/resources/tech-stack-explained).

## What each part of MERN does

MERN is four tools that together cover a whole web app: where the data lives, where the logic runs, how the logic is exposed to the outside, and what the user sees.

| Letter | Tool | Layer | Its job | Language |
|---|---|---|---|---|
| M | MongoDB | Database | Stores data as JSON-like documents in collections | Queries use a JSON-style syntax |
| E | Express | Server framework | Maps URLs and HTTP methods to functions (routes) and handles requests and responses | JavaScript |
| R | React | Front end | Builds the user interface from components and updates it when data changes | JavaScript (JSX) |
| N | Node.js | Runtime | Runs JavaScript on the server; Express runs on top of it | JavaScript |

The selling point is one language end to end, so you can move between front end and back end without switching syntax. The trade-off: MongoDB is a document database, so concepts such as joins and strict schemas work differently from SQL. Learn both; see [SQL interview questions](https://www.masaischool.com/resources/sql-interview-questions) and [SQL vs MySQL](https://www.masaischool.com/resources/sql-vs-mysql-difference) for the relational side.

## How one request travels through the stack

Take 'a user adds a note'. Every MERN app repeats this loop.

1. The user types a note in a React component and clicks Save.
2. React sends fetch('/api/notes', { method: 'POST', body: JSON.stringify(...) }) to the server.
3. Node.js receives the HTTP request; Express matches it to the POST /api/notes route.
4. The route handler validates the body and asks MongoDB to insert a document.
5. MongoDB stores it and returns the saved document, including its generated _id.
6. Express replies with JSON and a status code (201 for created, 400 for bad input).
7. React updates its state with the reply and re-renders the list.

If anything fails, the status code tells you which side to debug. A 400 means the request was wrong; a 500 means the server code or database failed; no response at all means the server is down or the URL is wrong.

## A working API you can run now (Node only, no database)

This server uses Node's built-in http module and an in-memory array in place of MongoDB, so it needs no installs. It starts on a free port, calls itself three times and shuts down. Output from a real run:const http = require("node:http"); const notes = []; let nextId = 1; function send(res, status, body) { res.writeHead(status, { "Content-Type": "application/json" }); res.end(JSON.stringify(body)); } const server = http.createServer(async (req, res) => { if (req.url === "/api/notes" && req.method === "GET") { return send(res, 200, notes); } if (req.url === "/api/notes" && req.method === "POST") { let raw = ""; for await (const chunk of req) raw += chunk; let data; try { data = JSON.parse(raw); } catch { return send(res, 400, { error: "invalid JSON" }); } if (typeof data.text !== "string" || !data.text.trim()) { return send(res, 400, { error: "text is required" }); } const note = { id: nextId++, text: data.text.trim() }; notes.push(note); return send(res, 201, note); } send(res, 404, { error: "not found" }); }); async function call(base, method, body) { const opts = { method, headers: { "Content-Type": "application/json" } }; if (body !== undefined) opts.body = JSON.stringify(body); const r = await fetch(base + "/api/notes", opts); console.log(method, r.status, JSON.stringify(await r.json())); } server.listen(0, "127.0.0.1", async () => { const base = "http://127.0.0.1:" + server.address().port; await call(base, "POST", { text: "learn Express" }); await call(base, "POST", { text: " " }); await call(base, "GET"); server.close(); server.closeAllConnections(); });

Output: POST 201 {"id":1,"text":"learn Express"}, then POST 400 {"error":"text is required"}, then GET 200 [{"id":1,"text":"learn Express"}]. The same API in Express is shorter. This version was not run here; Express was not installed.const express = require("express"); const app = express(); app.use(express.json()); const notes = []; let nextId = 1; app.get("/api/notes", (req, res) => res.json(notes)); app.post("/api/notes", (req, res) => { const text = req.body?.text; if (typeof text !== "string" || !text.trim()) { return res.status(400).json({ error: "text is required" }); } const note = { id: nextId++, text: text.trim() }; notes.push(note); res.status(201).json(note); }); app.listen(3000, () => console.log("API on http://localhost:3000"));

To replace the array with MongoDB you would use a library such as Mongoose. Again proofread only, and it needs a connection string to a running MongoDB:const mongoose = require("mongoose"); const Note = mongoose.model( "Note", new mongoose.Schema({ text: { type: String, required: true, trim: true } }) ); // connect once at start-up: await mongoose.connect(process.env.MONGODB_URI); app.get("/api/notes", async (req, res) => res.json(await Note.find())); app.post("/api/notes", async (req, res) => { const note = await Note.create({ text: req.body?.text }); res.status(201).json(note); });

Things the in-memory version teaches you: status codes, JSON parsing errors and validation. Things it hides: connection handling, indexes and what happens when two writes arrive at once. Put those into your project once you connect a real database.

## MERN vs MEAN and other stacks

| Stack | Front end | Back end and data | Choose it when |
|---|---|---|---|
| MERN | React | Node.js, Express, MongoDB | You want the most common JavaScript full-stack combination for projects and tutorials |
| MEAN | Angular (a full framework with TypeScript built in) | Node.js, Express, MongoDB | Your target team or college uses Angular |
| PERN | React | Node.js, Express, PostgreSQL | Your data is relational and you want SQL |
| Next.js plus a database | React with server rendering | Node.js routes, any database | You want one project for pages and API |
| Java with Spring Boot plus React | React | Java, Spring Boot, SQL | Your target employers are Java shops; see [Spring Boot interview questions](https://www.masaischool.com/resources/spring-boot-interview-questions) |
| Python (Django or FastAPI) plus React | React | Python, SQL | You work in data or AI and want a Python back end; see [Django vs Flask vs FastAPI](https://www.masaischool.com/resources/django-vs-flask-vs-fastapi) |

MERN versus MEAN comes down to React versus Angular. For the front-end side of that choice, read the [frontend developer roadmap](https://www.masaischool.com/resources/frontend-developer-roadmap). To learn TypeScript alongside either, see [TypeScript vs JavaScript](https://www.masaischool.com/resources/typescript-vs-javascript-difference). For the whole path, see the [full stack developer roadmap](https://www.masaischool.com/resources/full-stack-developer-roadmap).

## A free deploy path, as of 1 December 2026

Plans change, so check each page before you rely on it. This is what the vendors' own pages said on 1 December 2026.

| Part | Service | What the page says | Catch |
|---|---|---|---|
| Database | MongoDB Atlas free cluster | Listed as free forever, for learning, with 512MB storage and shared RAM and vCPU | Small and shared; not for production |
| API | Render free web service | Free web services are available; Render spins one down after 15 minutes without inbound traffic | The first request after idle is slow |
| React front end | Render static site, or Vercel Hobby | Render lists static sites as free; Vercel lists Hobby at $0 per month for personal projects | Hobby plans are for personal use; read the terms |

Keep the connection string in an environment variable, never in the repository. For more free hosting options, see [free hosting for AI-built apps](https://www.masaischool.com/resources/tools/free-hosting-for-ai-built-apps). For project ideas to build on this stack, see [full-stack projects with source code](https://www.masaischool.com/resources/projects/full-stack-projects-with-source-code) and [Node.js interview questions](https://www.masaischool.com/resources/nodejs-interview-questions).

## Frequently asked questions

### What is the MERN stack?

MERN stands for MongoDB, Express, React and Node.js. MongoDB is the database, Express is the server framework, React builds the user interface and Node.js runs JavaScript on the server. Because all four use JavaScript, one developer can build a whole web application in one language.

### What is the difference between MEAN and MERN?

The only difference is the front end. MEAN uses Angular, a full framework that uses TypeScript, while MERN uses React, a library focused on building interfaces. MongoDB, Express and Node.js are the same in both stacks, so the back end skills carry across.

### Is the MERN stack good for beginners?

It is a reasonable first full-stack path because you need only JavaScript. Learn JavaScript and basic HTML and CSS first, then Node and Express, then React, then MongoDB. The difficulty is the number of moving parts, so build small apps in steps rather than all at once.

### What projects can I build with the MERN stack?

Good first projects are a notes or to-do app with login, a blog with comments, an expense tracker, a URL shortener and a small shop with a cart. Each covers routes, a database and a React front end. Add authentication and deployment so the project is complete.

### Do I need to learn SQL if I learn MERN?

Yes, it is worth it. MongoDB suits flexible document data, but most employers also run relational databases, and interviews often ask SQL questions. Learning both lets you choose the right database per project and read other teams' code.

### Can I deploy a MERN app for free?

Yes, for learning and portfolio use. As of 1 December 2026, MongoDB Atlas lists a free cluster with 512MB, Render lists free web services and static sites, and Vercel lists a $0 Hobby plan. Free services have limits such as idle spin-down, so check current terms.

### Is the MERN stack still in demand?

No reliable demand figure was found for this page, so none is quoted. React and Node.js are widely used, and a MERN project shows full-stack skills. Check job posts in your city and count how many name React, Node.js and MongoDB before deciding.
