Introduction to MERN Stack | Download MongoDB & Express JS ๐๐
Our News App frontend is finally ready โ it fetches, paginates, and displays articles
beautifully with React. But right now, everything runs only in the browser. To make our
News App truly production-ready, with a real database, a real API, and real user data,
we need to step into the MERN Stack: MongoDB, Express.js, React.js, and Node.js.
In this tutorial, we will learn:
What is the MERN Stack?
MERN is a popular JavaScript full-stack technology bundle used to build dynamic, database-driven web applications end to end using a single language โ JavaScript. The name is an acronym made up of four technologies:
Together, these four technologies let developers write both the frontend and the backend in JavaScript โ which is exactly what makes MERN so beginner-friendly and efficient for projects like our News App.
---Why Use MERN Stack for Our News App?
Right now, our News App articles live only inside component state โ refresh the page and they're gone. With MERN, we can:
How Data Flows in a MERN Application
Understanding the request flow makes the rest of this series much easier to follow:
| Step | What Happens |
|---|---|
| 1 | React (frontend) sends a request to the Express server |
| 2 | Express (backend) receives the request and processes it via Node.js |
| 3 | Express queries or updates data in MongoDB |
| 4 | MongoDB sends the result back to Express |
| 5 | Express sends a JSON response back to React |
| 6 | React updates the UI with the new data |
Step 1: Download MongoDB
MongoDB is the database layer of our stack. To get started:
Step 2: Verify Your MongoDB Installation
Once installed, open your terminal or command prompt and check the version to confirm MongoDB was installed correctly.
mongod --version
You can also start the MongoDB shell to connect to your local database:
mongosh
If you see version numbers and a connected shell prompt, your MongoDB installation is working correctly and ready for our News App backend.
---Step 3: Set Up a Node Project
Before installing Express, we need a Node.js project. Create a new folder for your backend
and initialize it with npm.
mkdir news-app-backend
cd news-app-backend
npm init -y
This creates a package.json file that will track all our backend dependencies โ
including Express.
Step 4: Download & Install Express.js
Express.js is installed as an npm package inside your Node project โ there's no separate installer to download.
npm install express
Once installed, you'll see express listed under dependencies in your
package.json file.
Step 5: Create a Basic Express Server
Let's write a minimal index.js file to confirm Express is working.
const express = require("express");
const app = express();
const PORT = 5000;
app.get("/", (req, res) => {
res.send("Welcome to the News App Backend ๐ฐ๐");
});
app.listen(PORT, () => {
console.log(`Server running on http://localhost:${PORT}`);
});
Run the server with:
node index.js
Open http://localhost:5000 in your browser โ if you see the welcome message,
your Express server is up and running. ๐
MERN Stack Components at a Glance
| Technology | Role | Used For |
|---|---|---|
| MongoDB | Database | Storing news articles, users, and saved/bookmarked data |
| Express.js | Backend Framework | Building REST API routes and handling server logic |
| React.js | Frontend Library | Rendering the News App UI (already built!) |
| Node.js | Runtime Environment | Running JavaScript on the server |
Features and Learnings:-
mongod --version and mongosh.npm init.