A full-stack, catalog-style CRUD application for managing and browsing products by category — built with Node.js, Express, MongoDB, Mongoose, and EJS.
- View all products in a table
- Filter products by category
- Add new products (with name, price, image, category, and description)
- Edit existing products
- Delete products
- Product details page now shows creation and last updated timestamps
- Clean, responsive UI with EJS and Bootstrap 5
- Robust error handling for validation errors, invalid ObjectIds, and missing resources — all errors are shown on a custom, responsive error page for a better user experience.
- GET
/products– View all products - GET
/products/new– Open the form to add a new product - GET
/products/:id– View product details - GET
/products/:id/edit– Edit an existing product - DELETE
/products/:id– Delete a product (via form submission) - ERROR
/products/:invalidID– Displays a user-friendly error message for invalid requests or missing resources
Attempting to access a valid but non-existent product ID:
- Node.js
- Express
- MongoDB
- Mongoose
- EJS
- Bootstrap
npm installMongoDB must be running for the app to work. If it’s not running automatically, start it manually:
mongodTo populate your database with sample products, run:
node seeds.jsThis will clear any existing products and insert fresh seed data.
nodemon index.jsIf you don’t have nodemon installed globally, you can install it with
npm install -g nodemon, or simply runnode index.jsinstead. To stop the server, press Ctrl + C in the terminal.
The app will be available at http://localhost:3000/products.
index.js– Main Express app; sets up middleware, connects to MongoDB, mounts routers, and starts the server.routes/products.js– Router module containing all product-related routes.models/product.js– Mongoose schema and model definition.seeds.js– Script to seed the database with sample products.views/products/index.ejs– Displays the list of products.views/products/details.ejs– Shows individual product details.views/products/edit.ejs– Form to edit an existing product.views/products/new.ejs– Form to add a product.wrapAsync.js– Utility to catch async errors cleanly.appError.js– Custom error class for structured error responses.validateObjId.js– Middleware to handle invalid ObjectId formats.views/error.ejs– Styled error page for displaying validation errors, invalid ObjectIds, etc.
Contributions, issues, and suggestions are welcome!
Please read the Contributing Guidelines before making changes.
If you like this project, consider starring the repo to show your support!
This project is licensed under the MIT License - see the LICENSE file for details.