This project is a RESTful API for an e-commerce system built with Node.js, Express, and Sequelize ORM connecting to a MySQL database.
- Project Structure
- Database Schema
- Setup Instructions
- API Endpoints
- Environment Variables
- Technologies Used
The application uses the following database tables:
- Users: User accounts (
id,username,email,created_at) - Categories: Product categories (
id,name) - Products: Store products (
id,title,price,category_id,stock) - Orders: Customer orders (
id,user_id,total,status,created_at) - OrderDetails: Products within orders (
order_id,product_id,quantity,price)
-
Clone the repository:
git clone <repository_url> cd <repository_name>
-
Install dependencies:
npm install
-
Create a MySQL database.
-
Create a
.envfile with required environment variables (see Environment Variables). -
Run the application:
npm start
GET /api/users- Get all usersGET /api/users/:id- Get user by IDPOST /api/users- Create new userPATCH /api/users/:id- Update userDELETE /api/users/:id- Delete user
GET /api/products- Get all productsGET /api/products/:id- Get product by IDPOST /api/products- Create new productPATCH /api/products/:id- Update productDELETE /api/products/:id- Delete product
GET /api/categories- Get all categoriesGET /api/categories/:id- Get category by IDPOST /api/categories- Create new categoryPATCH /api/categories/:id- Update categoryDELETE /api/categories/:id- Delete category
GET /api/orders- Get all ordersGET /api/orders/:id- Get order by IDPOST /api/orders- Create new orderPATCH /api/orders/:id- Update order statusDELETE /api/orders/:id- Delete order
GET /api/orderDetails- Get all order detailsGET /api/orderDetails/:id- Get order detail by IDPOST /api/orderDetails- Add product to orderPATCH /api/orderDetails/:orderId/:productId- Update order detailDELETE /api/orderDetails/:id- Delete order detail
Create a .env file in the root directory and include the following variables:
DB_HOST=your_mysql_host
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=your_database_name
PORT=your_app_portReplace the placeholders with your actual credentials and configuration.
- Node.js
- Express.js
- Sequelize
- MySQL
- Express Validator