How to Build a Full Stack App Using MERN
The MERN stack—MongoDB, Express.js, React, and Node.js—is one of the most popular technology stacks for building full stack web applications using JavaScript from end to end.
In this beginner-friendly guide on CodeJourneyWithAamir, I’ll walk you through everything you need to know to build your first full stack web app using MERN, even if you're self-taught or just getting started in full stack development.
🚀 Why Learn MERN as a Beginner Developer?
As a junior developer, understanding how to connect the frontend and backend is crucial. The MERN stack allows you to:
- Use one language (JavaScript) for both frontend and backend.
- Learn industry-standard tools like React and Express.
- Build scalable and maintainable apps from scratch.
- Boost your portfolio with real-world, deployable projects.
📦 What is the MERN Stack?
🔹 MongoDB
A NoSQL database to store your application's data in flexible, JSON-like documents.
🔹 Express.js
A minimalist web framework for Node.js used to build RESTful APIs easily.
🔹 React.js
A JavaScript library for building user interfaces using components.
🔹 Node.js
A runtime environment that allows JavaScript to run on the server.
Together, these tools power everything from simple CRUD apps to complex enterprise-level systems.
🛠️ How to Build a Full Stack MERN App (Step-by-Step)
Let’s create a basic To-Do App using the MERN stack.
Step 1: Setup Your Folder Structure
mkdir mern-todo-app
cd mern-todo-app
mkdir backend frontend
Step 2: Initialize the Backend (Node.js + Express + MongoDB)
✅ Inside backend/
:
npm init -y
npm install express mongoose cors dotenv
Create index.js
:
const express = require('express');
const mongoose = require('mongoose');
const cors = require('cors');
require('dotenv').config();
const app = express();
app.use(cors());
app.use(express.json());
mongoose.connect(process.env.MONGO_URI, { useNewUrlParser: true, useUnifiedTopology: true })
.then(() => console.log("MongoDB connected"));
const taskSchema = new mongoose.Schema({ text: String });
const Task = mongoose.model('Task', taskSchema);
app.get('/tasks', async (req, res) => {
const tasks = await Task.find();
res.json(tasks);
});
app.post('/tasks', async (req, res) => {
const newTask = new Task({ text: req.body.text });
await newTask.save();
res.json(newTask);
});
app.listen(5000, () => console.log("Server running on port 5000"));
Create .env
:
MONGO_URI=mongodb://localhost:27017/mern-todo
Step 3: Initialize the Frontend (React)
✅ Inside frontend/
:
npx create-react-app .
npm install axios
Edit App.js
:
import React, { useEffect, useState } from 'react';
import axios from 'axios';
function App() {
const [tasks, setTasks] = useState([]);
const [text, setText] = useState('');
useEffect(() => {
axios.get('http://localhost:5000/tasks')
.then(res => setTasks(res.data));
}, []);
const addTask = () => {
axios.post('http://localhost:5000/tasks', { text })
.then(res => setTasks([...tasks, res.data]));
setText('');
};
return (
<div className="App">
<h1>MERN To-Do App</h1>
<input value={text} onChange={e => setText(e.target.value)} />
<button onClick={addTask}>Add</button>
<ul>
{tasks.map(task => <li key={task._id}>{task.text}</li>)}
</ul>
</div>
);
}
export default App;
🧩 Related Tools & Resources
- MongoDB Atlas – Cloud database hosting
- Postman – Test API endpoints
- Vercel or Render – For deploying frontend/backend
- 📚 Related Post: How to Deploy MongoDB on VPS
🧠Key Takeaways
- MERN stack allows end-to-end JavaScript development.
- You can build CRUD apps like To-Do lists using MongoDB, Express, React, and Node.js.
- Understanding the MERN stack improves your confidence in both frontend and backend logic.
💬 Final Thoughts
Now that you've built your first full stack MERN app, what will you create next? Try extending this project by adding:
- Delete and edit functionality
- Authentication (using JWT)
- Deployment to cloud platforms
👉 Comment your thoughts below, share this post with a fellow coder, and don’t forget to subscribe to CodeJourneyWithAamir for more beginner-friendly tutorials!
Tags: MERN Stack, Full Stack Development, JavaScript Projects, React Tutorials, Node.js Backend, MongoDB, Express.js, Web Development, Beginner Coding
Hi Everyone, please do not spam in comments.