This repository contains a functional Express.js API that connects to a MySQL database using Sequelize. It provides routes to perform CRUD operations on categories, products, and tags.
https://github.com/mlukicdesign/eCommerce-Backend
https://drive.google.com/file/d/1Uy-zmjvtiUzYstg_HnaH4j8ytk93RW9M/view
- Clone the repository and navigate to the project directory.
- Create an environment variable file (.env) in the root directory and add the following information:
Replace
DB_NAME=your_database_name DB_USER=your_mysql_username DB_PASSWORD=your_mysql_passwordyour_database_name,your_mysql_username, andyour_mysql_passwordwith your own database credentials. - Install the dependencies by running
npm install. - Use the provided schema and seed files to set up a development database. Run the following commands:
This will create the necessary tables in the database and populate them with test data.
mysql -u your_username -p source ./db/schema.sql; node seeds/index.js - Start the application by running
npm startor, run the Nodemon server withnpm run watch. The Sequelize models will be synced with the MySQL database, and the server will be started.
Once the application is running, you can use a tool like Insomnia to interact with the API.
-
Categories: Use the GET route
/api/categoriesto retrieve all categories and their associated products. The data will be returned in a formatted JSON. -
Products: Use the GET route
/api/productsto retrieve all products and their associated categories and tags. The data will be returned in a formatted JSON. -
Tags: Use the GET route
/api/tagsto retrieve all tags and their associated products. The data will be returned in a formatted JSON.
You can test the POST, PUT, and DELETE routes using Insomnia Core.
-
POST: Use the appropriate route (e.g.,
/api/categories) with the relevant request payload to create new data in the database. -
PUT: Use the appropriate route with the relevant resource ID (e.g.,
/api/categories/:id) and the updated data in the request payload to update existing data in the database. -
DELETE: Use the appropriate route with the relevant resource ID to delete data from the database.
Make sure to replace :id in the route with the actual ID of the resource you want to modify or delete.
This eCommerce Backend with Sequelize provides a simple and functional backend for managing categories, products, and tags in a MySQL database. It allows for easy creation, retrieval, update, and deletion of data using HTTP requests. Feel free to explore and modify the code according to your specific requirements.
https://github.com/mlukicdesign
thanks for viewing :)
