Full-stack CRUD app with MongoDB Atlas, Express, React, and Node.js (MERN). Covers REST APIs, MongoDB driver and React Router.
Full-stack CRUD app with MongoDB Atlas, Express, React, and Node.js (MERN). Covers REST APIs, MongoDB driver and React Router.
A full-stack CRUD application built with MongoDB, Express, React, and Node.js (MERN).
Companion code for the MERN Stack Tutorial and video walkthrough.
This project demonstrates an employee record tracker:
The React app in mern/client calls an Express API in mern/server, and data is stored in MongoDB Atlas.
…Stack:
employees.records collection)mern/
client/ # React + Vite frontend
server/ # Express API + MongoDB integration# 1) Clone
git clone https://github.com/mongodb-developer/mern-stack-example.git
cd mern-stack-example
# 2) Create server environment file
cp mern/server/config.env.example mern/server/config.envUpdate mern/server/config.env with one of the following ATLAS_URI values:
Atlas cluster:
ATLAS_URI=mongodb+srv://:@.mongodb.net/
PORT=5050If you are new to Atlas, use the Atlas quick start guide and then paste your connection string into ATLAS_URI.
Optional: seed sample data:
cd mern/server && node seed.jsStart the backend API:
cd mern/server
npm install
npm startStart the frontend in a second terminal:
cd mern/client
npm install
npm run devOpen http://localhost:5173.
GitHub Codespaces is an easy and fast way to get this project running without installing anything locally. It uses a dev container, which is a Docker environment configured for development.
Base URL: http://localhost:5050
| Method | Endpoint | Description |
|---|---|---|
GET |
/record |
Retrieve all records |
GET |
/record/:id |
Retrieve one record by ID |
POST |
/record |
Create a record |
PATCH |
/record/:id |
Update a record |
DELETE |
/record/:id |
Delete a record |
Example request body for create or update:
{
"name": "Jane Smith",
"position": "Developer",
"level": "Senior"
}| Feature | Where |
|---|---|
| MongoDB Node.js Driver | mern/server/db/connection.js |
| CRUD operations | mern/server/routes/record.js |
| MongoDB Atlas | ATLAS_URI in config.env |
| Server API version | ServerApiVersion.v1 in connection.js |
ATLAS_URI in mern/server/config.envmern/server/config.envnode --versionmern/server/config.env existsmern/server: npm install:5050node seed.js in the server folder)PORT in mern/server/config.env, or stop the process using :5050This repository is for educational use and is not a supported MongoDB product.
No open issues yet, or sync has not completed.