Project: Full MERN Back-End
Build a complete, persistent back-end: Express + Mongoose + MongoDB with full CRUD and validation.
What you will learn
- Build a production-shaped back-end
- Persist data in MongoDB via Mongoose
- Structure the project properly
The brief
Build the complete back-end for an app of your choice (tasks, blog, products). This is the “EN-M” of MERN, ready for a React front-end.
Requirements
- Express server with
express.json()andcors(). - MongoDB connection via Mongoose, using a
.envconnection string. - A schema/model with validation.
- Full CRUD routes (list, get one, create, update, delete) in a
Router. - Proper status codes, a 404 handler and a central error handler.
- All async routes wrapped in
try/catch.
Suggested structure
server/
models/ Task.js (schema + model)
routes/ tasks.js (the CRUD router)
server.js (connect db, middleware, mount routes)
.env (MONGO_URI, PORT)Each part has one job. models/Task.js holds the Mongoose schema and model (the shape of your data). routes/tasks.js holds the CRUD router (the URLs clients call). server.js is the entry point that connects to the database, sets up middleware like express.json() and cors(), and mounts the router. (CORS stands for *Cross-Origin Resource Sharing* — a browser rule about which web addresses may call your API; the cors() middleware switches on permission so your React app, running on a different address, is allowed to talk to this server.) .env keeps secrets like MONGO_URI and PORT out of your code. Splitting files this way keeps the project tidy as it grows.
A sensible order to build it in:
- Set up
.envwith yourMONGO_URIandPORT, and add.envto.gitignore. - In
server.js, create the Express app, addexpress.json()andcors(), and connect Mongoose. - Write the schema and model in
models/Task.js(with validation rules). - Build the CRUD routes in
routes/tasks.js, eachasyncand wrapped intry/catch. - Mount the router in
server.jsand add a 404 handler and a central error handler. - Start the server, test every endpoint, then restart and confirm the data is still there.
Tip: Test every endpoint with Postman / Thunder Client. Then restart the server and confirm the data persists — that is the whole point of a real database.
✍️ Practice
- Build the full back-end meeting all six requirements.
- Confirm data persists across server restarts.
🏠 Homework
- Add validation error messages and a search/filter query parameter to your list route.