Skip to content
/ ECOM Public

ECOM Backend (MERN) A simple e-commerce backend built with MongoDB, Express, and Node.js. Handles users, products, carts, and orders. Auth with JWT and email verification is included.

Notifications You must be signed in to change notification settings

Louis2324/ECOM

Repository files navigation

ECOM MVP Backend (MERN)

A simple e-commerce backend built with MongoDB, Express, and Node.js.
Handles users, products, carts, and orders with JWT authentication and email verification.


Features

  • User Authentication
    • Register, login, and email verification
    • JWT-based route protection
  • Products
    • Admin can create, update, delete products
    • All users can view products
    • Supports filtering (category, price) and sorting (price, name, createdAt)
  • Cart
    • Add, update, remove, or clear items
    • Cart is tied to a specific user
  • Orders
    • Checkout cart and create order
    • Stock is updated on checkout
  • Validation & Error Handling
    • Joi validation for requests
    • Global error handling middleware
  • Environment Config
    • .env with MongoDB, JWT, and email settings
  • Security
    • Admin routes protected by isAdmin middleware
    • Users cannot buy more than available stock

Environment Variables (.env)

# Server
PORT=5000
NODE_ENV=development

# MongoDB
MONGO_URI=your_mongodb_connection_string

# JWT
JWT_SECRET_KEY=your_jwt_secret_key

# Email (Nodemailer)
EMAIL_USER=your_email@example.com
EMAIL_PASS=your_email_password


## API Routes 

## Auth

### POST `/api/auth/register`
Register a new user.

### POST `/api/auth/login`
Login a user and return a JWT token.

### GET `/api/auth/verify-email/`
Verify a user's email using the verification code.

---

## Products

### GET `/api/products`
List all products. Supports optional query filters: category, minPrice, maxPrice, and sorting.

### GET `/api/products/:id`
Retrieve a single product by its ID.

### POST `/api/products` (Admin only)
Create a new product.

### PUT `/api/products/:id` (Admin only)
Update an existing product.

### DELETE `/api/products/:id` (Admin only)
Delete a product.

---

## Cart

### GET `/api/cart`
Retrieve the current user's cart.

### POST `/api/cart/add`
Add a product to the cart.

### PUT `/api/cart/update`
Update the quantity of a product in the cart.

### DELETE `/api/cart/delete`
Remove a product from the cart.

### DELETE `/api/cart/clear`
Clear all items from the cart.

---

## Orders

### POST `/api/orders/checkout`
Checkout the current cart, create an order, and update product stock.

About

ECOM Backend (MERN) A simple e-commerce backend built with MongoDB, Express, and Node.js. Handles users, products, carts, and orders. Auth with JWT and email verification is included.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published