ECommerce Back-End is a back-end application that utilizes Sequelize, Express.js, and MySQL to build data structures from the server-side api to the database.
This application was refactored from a working application that used Express.js to using Sequelize to interact with a MySQL database instead. Working on this application gave me an understanding of how e-commerce platforms work to provide a suite of services using a relational database like SQL.
This application is run using the user's terminal. Before running this application, please see the Installation section.
This application can be invoked using the command npm start
, which starts the server. If users wish to test the back-end routes without a front-end user interface available, they can use Insomnia, a free application that allows you to test and validate results of RESTful applications. Once the server is started, users can test the following routes:
- Using a GET request to the api endpoint
localhost:3001/api/[model_name]
will return all instances of that model. Currently, there are three different models you can test:/api/categories
will return all categories./api/products
will return all products./api/tags
will return all product tags.
Here's a link to the video version of the above gif.
- Using a GET request to the api endpoint
localhost:3001/api/[model_name]/[id]
will return the category, product, or tag with the specified id. Currently, there are three different models you can test:/api/categories/[id]
will return a single item with the specified id from categories./api/products/[id]
will return a single item with the specified id from products./api/tags/[id]
will return a single item with the specified id from product tags.
Here's a link to the video version of the above gif.
- Navigate to the api endpoint
localhost:3001/api/[model_name]
. Using a POST request from here will allow you to create a new category, product, or tag, as long as you input all of the necessary fields of information./api/categories
requires that your data looks like this, where[category_name]
is the name of the category you intend to add{ "category_name": "[category_name]" }
/api/products
requires that your data looks like this, where:[product_name]
is the name of the product you intend to add[integer]
is price you wish to list the item under or the number of these items you have in stock as an integer[category_id]
is the id number of the category to which you are adding this product as an integer
{ "product_name": "[product_name]", "price": [integer], "stock": [integer], "category_id": [category_id] }
/api/tags
requires that your data looks like this, where[tag_name]
is the name of the tag you intend to add{ "tag_name": "[tag_name]" }
Here's a link to the video version of the above gif.
- Navigate to the api endpoint
localhost:3001/api/[model_name]/[id]
. Using a PUT request from here will allow you to edit the category, product, or tag of the id number you specified. See above as a reference to the fields you can change using this request.
Here's a link to the video version of the above gif.
- Navigate to the api endpoint
localhost:3001/api/[model_name]/[id]
. Using a DELETE request from here will allow you to delete the category, product, or tag of the id number you specified.
Here's a link to the video version of the above gif.
In order to use this application, you will need to install it on your local computer.
- Open the command line interface.
- Clone the repository onto your local machine using the
git clone
command. - Once the repository has been cloned, navigate into the root directory of the application using the command
cd ECommerce-Back-End
. - This application has dependencies that must be installed prior to running the application (i.e. dotenv, inquirer, MySQL2, and console.table). Run the command
npm install
to install necessary packages and dependencies. - This application relies on private enviromental variables. In the main directory of the application, create a
.env
file.- The contents of your
.env
file should look like this, where [MySQL username] is your MySQL username, and [MySQL password] is your MySQL password:
DB_NAME="ecommerce_db" DB_USER="[MySQL username]" DB_PW="[MySQL password]"
- For example, if my username is
ashlynn4567
and my password ispassword1234
, my.env
file will look like the following:
DB_NAME="ecommerce_db" DB_USER="ashlynn4567" DB_PW="password1234"
- The contents of your
- Next, you will need to seed the data. Note: You must have MySQL installed on your computer in order to seed the data.
- Log in to MySQL in your command line with the command
mysql -u root -p
. - Enter your login credentials.
- Type the command
source db/schema.sql
. - Quit MySQL with the command
quit
.
- Log in to MySQL in your command line with the command
- After quitting from MySQL, seed the database by running the command
npm run seed
in your terminal. - Now you can start the application. Enter the command
npm start
in your terminal to begin. - If you wish to stop the server at any time, simply type
ctrl + C
in your terminal.
For further help with installation, please refer to the below demonstration video.
Here's a link to the video version of the above gif.
- JavaScript
- Node.js
- npm
- dotenv
- MySQL2
- Sequelize.js
- Express.js
In the future, I would like to add the following improvements:
- Although this project was created with a focus on back-end, I would love to connect it to a working front-end to make it a full stack application.
I'm always interested in refactoring code to improve it's functionality. If you would like to suggest your own improvements, you can reach me at the links below.
This project was built with the help of the University of Oregon's Coding Boot Camp.
The application is covered under the following license: MIT