This application was created with Express.js, Node.js, and Sequelize. This application creates a back end for an e-commerce website.
- Technology Stack
- User Story
- Acceptance Criteria
- Installation
- API Routes
- Screenshot
- Usage
- License
- Contributors
- Outside Resources
- Questions
AS A manager at an internet retail company
I WANT a back end for my e-commerce website that uses the latest technologies
SO THAT my company can compete with other e-commerce companies
GIVEN a functional Express.js API
WHEN I add my database name, MySQL username, and MySQL password
to an environment variable file
THEN I am able to connect to a database using Sequelize
WHEN I enter schema and seed commands
THEN a development database is created and is seeded with test data
WHEN I enter the command to invoke the application
THEN my server is started and the Sequelize models are synced
to the MySQL database
WHEN I open API GET routes in Insomnia Core for categories, products,
or tags
THEN the data for each of these routes is displayed in a formatted
JSON
WHEN I test API POST, PUT, and DELETE routes in Insomnia Core
THEN I am able to successfully create, update, and delete data in
my database
-
Clone the repository.
git clone git@github.com:erin-m-keller/keller-ecommerce.git
- Install the dependencies.
- Install MySQL
cd keller-ecommerce npm i
- CD into the db directory
cd db
Start the MySQL server in the terminal (ensure you are in the db directory of the project)
- mysql -u root -p
Enter the password
password_goes_here
Once MySQL server has started, create the database
SOURCE createDatabase.sql
Exit the MySQL server
exit OR quit
- Return to the root directory
cd ..
Update .env.example in the root directory and set your local MySQL server username and password. Then rename to .env
Don't worry, your credentials will only be saved to your local machine. The .env file is in .gitignore
DB_NAME = "" DB_USER = "" DB_PW = ""
Seed the database
npm run seed
Start the application
npm start
Once the server is listening use the below commands in Insomnia/Postman to view the data
- Get all categories and their associated products:
- GET localhost:3001/api/categories
- Get one category based on id with their associated products:
- GET localhost:3001/api/categories/:id
- Create a new category:
- POST localhost:3001/api/categories
- Set Body to JSON, then use the following data structure:
{ "name": "name here" }
- Update a category:
- PUT localhost:3001/api/categories/:id
- Set Body to JSON, then use the following data structure:
{ "name": "name here" }
- Delete a category:
- DELETE localhost:3001/api/categories/:id
- Get all tags and their associated products:
- GET localhost:3001/api/tags
- Get one tag based on id with their associated products:
- GET localhost:3001/api/tags/:id
- Create a new tag:
- POST localhost:3001/api/tags
- Set Body to JSON, then use the following data structure:
{ "name": "name here" }
- Update a tag:
- PUT localhost:3001/api/tags/:id
- Set Body to JSON, then use the following data structure:
{ "name": "name here" }
- Delete a tag:
- DELETE localhost:3001/api/tags/:id
- Get all products and their associated categories and tags:
- GET localhost:3001/api/products
- Get one product based on id with their associated categories and tags:
- GET localhost:3001/api/products/:id
- Create a new product:
- POST localhost:3001/api/product
- Set Body to JSON, then use the following data structure:
{ "product_name": "name here", "price": 200.00, "stock": 3, "tagIds": [1, 2, 3, 4], "category_id": 1 }
- Update a product:
- PUT localhost:3001/api/products/:id
- Set Body to JSON, then use the following data structure:
{ "product_name": "Unicorn 4", "price": 11.50, "stock": 16, "category_id": 4, "tags": [ { "tag_id": 1 }, { "tag_id": 7 } ] }
- Delete a product:
- DELETE localhost:3001/api/products/:id
keller-ecommerce.mp4
Click to play!
- ChatGPT: Used ChatGPT to generate the regex used within the validate functions.
If you have any questions about this project, please contact me directly at aestheticartist@gmail.com.
You can view more of my projects here. - Install the dependencies.