Skip to content
Concept ยท Software Development

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

Younus FardeenBy Younus FardeenUpdated 1 Dec 20267 min read
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.

On this pageWhat each part of MERN doesHow one request travels through the stackA working API you can run now (Node only, no database)MERN vs MEAN and other stacksA free deploy path, as of 1 December 2026Frequently asked questions

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.

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.

LetterToolLayerIts jobLanguage
MMongoDBDatabaseStores data as JSON-like documents in collectionsQueries use a JSON-style syntax
EExpressServer frameworkMaps URLs and HTTP methods to functions (routes) and handles requests and responsesJavaScript
RReactFront endBuilds the user interface from components and updates it when data changesJavaScript (JSX)
NNode.jsRuntimeRuns JavaScript on the server; Express runs on top of itJavaScript

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 and SQL vs MySQL 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

StackFront endBack end and dataChoose it when
MERNReactNode.js, Express, MongoDBYou want the most common JavaScript full-stack combination for projects and tutorials
MEANAngular (a full framework with TypeScript built in)Node.js, Express, MongoDBYour target team or college uses Angular
PERNReactNode.js, Express, PostgreSQLYour data is relational and you want SQL
Next.js plus a databaseReact with server renderingNode.js routes, any databaseYou want one project for pages and API
Java with Spring Boot plus ReactReactJava, Spring Boot, SQLYour target employers are Java shops; see Spring Boot interview questions
Python (Django or FastAPI) plus ReactReactPython, SQLYou work in data or AI and want a Python back end; see 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. To learn TypeScript alongside either, see TypeScript vs JavaScript. For the whole path, see the 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.

PartServiceWhat the page saysCatch
DatabaseMongoDB Atlas free clusterListed as free forever, for learning, with 512MB storage and shared RAM and vCPUSmall and shared; not for production
APIRender free web serviceFree web services are available; Render spins one down after 15 minutes without inbound trafficThe first request after idle is slow
React front endRender static site, or Vercel HobbyRender lists static sites as free; Vercel lists Hobby at $0 per month for personal projectsHobby 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. For project ideas to build on this stack, see full-stack projects with source code and Node.js 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.

Learn this with mentors

Programmes for builders and engineers with admissions open: live classes, mentors and project work.

Continue learning

Roadmap

Full stack developer roadmap

Eight stages from HTML to deployed apps, each with a free resource

7 min read
Roadmap

Frontend developer roadmap

HTML, CSS, JavaScript, React and the quality skills that follow

6 min read
Concept

Tech stack explained

Layers of a tech stack, seven real examples, and how to pick one.

6 min read