This is the back-end for an e-commerce site, designed to manage a product catalog, including categories, tags, and product listings. The application uses Express.js as the server framework, Sequelize as the ORM (Object-Relational Mapping) tool, and PostgreSQL as the database. This project provides a RESTful API for handling CRUD operations on products, categories, and tags.
- Clone the repository:
git clone <repository-url>
- Navigate to the project directory:
cd e-commerce-back-end - Install the dependencies:
npm install
- Create a
.envfile and configure the following environment variables:DB_NAME='your_database_name' DB_USER='your_database_username' DB_PASSWORD='your_database_password' DB_HOST='localhost' DB_PORT=5432
- Initialize the database:
npx sequelize-cli db:create npx sequelize-cli db:migrate
- Seed the database (optional for testing):
npm run seed
- Start the server:
npm start
This project provides API endpoints to manage products, categories, and tags. You can interact with these endpoints through a tool like Insomnia or Postman to test the back-end functionality.
- GET
/api/categories: Retrieves all categories. - GET
/api/categories/:id: Retrieves a category by its ID. - POST
/api/categories: Creates a new category. - PUT
/api/categories/:id: Updates an existing category by ID. - DELETE
/api/categories/:id: Deletes a category by ID.
- GET
/api/products: Retrieves all products. - GET
/api/products/:id: Retrieves a product by its ID. - POST
/api/products: Creates a new product. - PUT
/api/products/:id: Updates an existing product by ID. - DELETE
/api/products/:id: Deletes a product by ID.
- GET
/api/tags: Retrieves all tags. - GET
/api/tags/:id: Retrieves a tag by its ID. - POST
/api/tags: Creates a new tag. - PUT
/api/tags/:id: Updates an existing tag by ID. - DELETE
/api/tags/:id: Deletes a tag by ID.
- Install Insomnia or any API client.
- Make sure your server is running by executing:
npm start
- In Insomnia, create requests for the different routes.
-
Example to retrieve all categories:
- Method: GET
- URL:
http://localhost:3001/api/categories
-
Example to create a new product:
- Method: POST
- URL:
http://localhost:3001/api/products - Body:
{ "product_name": "New Product", "price": 29.99, "stock": 10, "category_id": 1, "tagIds": [1, 2] }
- Node.js
- Express.js
- Sequelize
- PostgreSQL
- dotenv
- Bcrypt
- Express-session
This project is licensed under the MIT License.