A Node.js + Express backend for a MongoDB e-commerce store. Supports product CRUD, cart management, and basic shopping flow for frontend or API clients.
- Manages products with create, read, update, and delete operations
- Tracks a shopping cart with add, update, remove, and clear functionality
- Uses MongoDB for data storage
- Includes error handling and schema validation in controllers
- Clone the repository:
git clone https://github.com/AODO123/final-project.git cd "final-project"
- Install dependencies:
npm install
- Create a
.envfile in the project root with:PORT=3000 MONGO_URI=mongodb://127.0.0.1:27017/final-project
- Seed sample data:
npm run seed
Start the server
npm startThen open http://localhost:3000 and use your API client to call the endpoints.
GET /api/products— list all productsGET /api/products/:id— get product detailsPOST /api/products— create a productPUT /api/products/:id— update a productDELETE /api/products/:id— delete a product
POST /api/carts— create a cartGET /api/carts/:id— get a cart by IDPOST /api/carts/:id/items— add an item to the cartPUT /api/carts/:id/items/:productId— update item quantityDELETE /api/carts/:id/items/:productId— remove an item from the cartDELETE /api/carts/:id— clear the cart
Product:
{
"name": "New item",
"price": 10,
"description": "Test product",
"category": "general",
"image": "https://example.com/image.png",
"stock": 5
}Add to cart:
{
"productId": "<existing product id>",
"quantity": 2
}- Ensure MongoDB is running before starting the server.
- Update
MONGO_URIin.envif needed. - Use Postman to test the endpoints.
eCommerce API that is a backend service that enables shoppers to browse products, build and manage shopping carts, and allows admins to create, update, and maintain product listings.
- As a shopper, I can view products.
- As a shopper, I can search or filter products.
- As a shopper, I can create a cart and add items to it.
- As a shopper, I can update cart item quantities and remove items.
- As an admin, I can add or edit products.
- As an admin, I can delete product listings when needed.