This API was created to perform CRUD operations on the simple elements that can occur on a standard E-Commerce
project. This application has Products, Tags and Categories that interact with each other depending on the request.
Since the main focus was creating the API for this project, there is no front-end that allows the user to interact with it so, I've used Postman
during testing and Insomnia
for the demonstration.
This API uses Express.js
to run the server and Sequelize
to interact with the MySQL
database.
This was my first time creating a fully interactive back-end using MySQL
. Sequelize
makes it so much easier to interact with the database while keeping the code clean. I've noticed that once the API handles with PUT requests, it's best for the user to be inputting specifically the required fields otherwise, things can get messy and the user might come across with errors. Handling the errors and giving back descriptive messages is also very helpful on troubleshooting and for the user experience.
I used async
& await
while coding the routes, I also used try...catch
for the first time. It definitely shortens the code while getting rid of call-back hell.
- Alternatively, simply in the terminal;
git clone https://github.com/kemaldemirgil/buy-m3
- Once it's located in your PC, before adding anything yet, please create the database from the
MySQL
shell. The schema is located indb/schema.sql
.Create Database
- Alternatively, copy the following:
-- DROP DATABASE DROP DATABASE IF EXISTS ecommerce_db; -- CREATE DATABASE CREATE DATABASE ecommerce_db;
- After creating the database, please create a
.env
file to store your username, password and the database name using the following:DB_USER= DB_PW= DB_NAME=ecommerce_db
Seed Database - After creating the
.env
file, please seed the database by opening the terminal in the parent directory by running;npm run seed
Seed Database - Next, please install the dependencies by running the terminal in the parent directory.
npm i
Install Dependencies - Finally, to start the application, please run the following on the main file:
Alternatively, to run it using
npm start
nodemon
,npm run watch
CRUD on Categories |
---|
CRUD on Tags |
---|
CRUD on Products |
---|
Please contact me for any contributions or any input about this application, I would love to get some feedback!
Copyright © Kemal Demirgil. All rights reserved. Licensed under the MIT license.