A full-stack CRUD application built with MongoDB, Express, Angular, and Node.js (MEAN).
Companion code for the MEAN Stack Tutorial.
This project demonstrates an employee record tracker:
- Create records
- Read records from MongoDB
- Update records
- Delete records
The Angular app in client calls an Express API in server, and data is stored in MongoDB.
┌─────────────────────┐ REST (JSON) ┌──────────────────────────┐
│ Angular (CLI) │ ─────────────────────► │ Express API │
│ client │ ◄───────────────────── │ server │
│ :4200 │ │ :5300 │
└─────────────────────┘ └───────────┬──────────────┘
│ MongoDB Node.js driver
▼
┌──────────────────────────┐
│ MongoDB │
│ database: meanStackExample
│ collection: employees │
└──────────────────────────┘
Stack:
- Frontend: Angular 21, Angular Material
- Backend: Node.js, Express 4, TypeScript, MongoDB Node.js Driver 6
- Database: MongoDB (
meanStackExample.employeescollection)
client/ # Angular frontend
server/ # Express API + MongoDB integration
- Node.js 20+
- npm 9+
- A local MongoDB instance or a free MongoDB Atlas cluster
# 1) Clone
git clone https://github.com/mongodb-developer/mean-stack-example.git
cd mean-stack-example
# 2) Create server environment file
cp server/.env.example server/.envUpdate server/.env with one of the following DATABASE_URI values:
Local MongoDB:
DATABASE_URI=mongodb://localhost:27017/
PORT=5300Atlas cluster:
DATABASE_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/
PORT=5300If you are new to Atlas, use the Atlas quick start guide and then paste your connection string into DATABASE_URI.
Optional: seed sample data:
(cd server && npm install && npm run seed)Start the backend API:
cd server
npm startStart the frontend in a second terminal:
cd client
npm install
npm startOpen http://localhost:4200.
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:5300
| Method | Endpoint | Description |
|---|---|---|
GET |
/healthcheck |
Check API readiness |
GET |
/employees |
Retrieve all employees |
GET |
/employees/:id |
Retrieve one employee by ID |
POST |
/employees |
Create an employee |
PUT |
/employees/:id |
Update an employee |
DELETE |
/employees/:id |
Delete an employee |
Example request body for create or update:
{
"name": "Jane Smith",
"position": "Developer",
"level": "senior"
}| Feature | Where |
|---|---|
| MongoDB Node.js Driver | server/src/database.ts |
| CRUD operations | server/src/employee.routes.ts |
| MongoDB schema validation | startup validation in server/src/database.ts |
| Environment-based connection setup | DATABASE_URI in server/.env |
- Verify
DATABASE_URIinserver/.env - Confirm your database user credentials are correct (Atlas)
- Confirm your IP is in Atlas Network Access
- Check Node version:
node --version - Confirm
server/.envexists - Reinstall dependencies in
server:npm install
- Confirm backend is running on
:5300 - Open browser dev tools and check network requests
- Confirm records exist in MongoDB (or run
cd server && npm run seed)
- Change
PORTinserver/.env, or stop the process using:5300
- Use GitHub Issues for bugs and feature requests
- Use MongoDB Community Forums for general MongoDB questions
This repository is for educational use and is not a supported MongoDB product.