This is a backend API service for an e-commerce platform built with Node.js, Express, and MongoDB. It features robust user authentication via JWT, secure password hashing with bcrypt, CRUD operations on products, and integration with a Currency Exchange Rate API to convert product prices into different currencies.
β config/ β controllers/ β middleware/ β models/ β routes/ β utils/ β index.ts β .env β package.json
β’ User Registration & Login β’ JWT Authentication β’ Password Hashing (bcrypt) β’ Product CRUD Operations β’ Currency Conversion using a 3rd-Party API β’ Input Validation (Joi) β’ Centralized Error Handling β’ API Documentation with Swagger/Postman
β’ Node.js v16+ β’ MongoDB β’ npm or yarn
-
Clone the repository https://github.com/jxwatson251/E-commerce-Platform.git cd E-commerce-Platform
-
Install dependencies npm install
-
Create a .env file PORT=5000 MONGODB_URI=mongodb://localhost:27017/ecommerce JWT_SECRET=your_jwt_secret EXCHANGE_API_URL=https://api.exchangerate-api.com/v4/latest/USD
-
Start the server npm start
| Endpoint | Method | Description |
|---|---|---|
| /api/auth/register | POST | Register a new user |
| /api/auth/login | POST | Login and receive JWT |
| /api/users/me | GET | Get user profile (auth) |
| /api/users/me | PUT | Update profile (auth) |
| Endpoint | Method | Access | Description |
|---|---|---|---|
| /api/products | GET | Public | Get all products |
| /api/products/:id | GET | Public | Get product by ID |
| /api/products | POST | Authenticated | Create a new product |
| /api/products/:id | PUT | Authenticated | Update product (owner only) |
| /api/products/:id | DELETE | Authenticated | Delete product (owner only) |
| /api/products/:id/price-in/:currency | GET | Public | Get price in another currency |
β’ Request validation via Joi β’ Centralized error middleware β’ Meaningful HTTP status codes and messages
β’ View the full API documentation via: β’ Swagger UI (if implemented) β’ Postman Collection: Link to Collection