This project is an e-commerce application backend built with Node.js, Express.js, MySQL, Sequelize ORM, and implements REST API for communication.
- Introduction
- Features
- Technologies Used
- Setup
- Usage
- API Endpoints
- Database Schema
- Contributing
- License
This repository contains the backend implementation of an e-commerce application. It provides functionalities for managing products, orders, users, and authentication.
- Authentication and authorization using JWT tokens.
- CRUD operations for products, orders, and users.
- Database interactions using Sequelize ORM.
- RESTful API design for seamless client-server communication.
- Node.js
- Express.js
- MySQL
- Sequelize ORM
- JSON Web Tokens (JWT)
- bcryptjs
- body-parser
- cors
- dotenv
To run this project locally, follow these steps:
-
Clone the repository:
git clone <repository-url> cd <repository-name>
-
Install dependencies:
npm install
-
Set up environment variables:
Create a
.env
file in the root directory and add the following variables:PORT=3000 DB_HOST=localhost DB_USER=root DB_PASSWORD=your_password DB_NAME=ecommerce_db JWT_SECRET=your_jwt_secret
-
Initialize the database:
Ensure MySQL is running, then run Sequelize migrations to set up the database schema:
npx sequelize-cli db:migrate
-
Start the server:
npm start
-
Access the API:
The API will be available at
http://localhost:3000
.
To use the API, refer to the API endpoints section below for available routes and request methods.
Below are the main API endpoints:
- GET /api/products: Fetch all products.
- POST /api/products: Create a new product.
- GET /api/products/:id: Fetch a single product by ID.
- PUT /api/products/:id: Update a product by ID.
- DELETE /api/products/:id: Delete a product by ID.
- GET /api/orders: Fetch all orders.
- POST /api/orders: Create a new order.
- GET /api/orders/:id: Fetch a single order by ID.
- PUT /api/orders/:id: Update an order by ID.
- DELETE /api/orders/:id: Delete an order by ID.
- POST /api/auth/login: User login endpoint.
- POST /api/auth/register: User registration endpoint.
The database schema includes tables for users
, products
, orders
, etc. For detailed schema, refer to Sequelize models in the models
directory.
Contributions are welcome. For major changes, please open an issue first to discuss what you would like to change.
ISC