The company stakeholders want to create an online storefront to showcase their great product ideas. Users need to be able to browse an index of all products, see the specifics of a single product, and add products to an order that they can view in a cart page. I have been tasked with building the API that will support this application, and my coworker who is building the frontend.
First, clone this repo:
git clone https://github.com/wmuza/Storefront-Backend-Project.git
Then switch into the repo folder
cd Storefront-Backend-Project
Our database will be running on the default port 5432 and our webserver will be ruunig on port 3000
- switch to the postgres user
su postgres
- start psql
psql postgres
- in psql run the following:
CREATE USER shopping_user WITH PASSWORD 'password123';
CREATE DATABASE shopping;
\c shopping
GRANT ALL PRIVILEGES ON DATABASE shopping TO shopping_user;
- to test that it is working run
\dt
and it should output "No relations found."
- switch to the postgres database
\c postgres
- run the following:
CREATE DATABASE shopping_test;
\c shopping_test
GRANT ALL PRIVILEGES ON DATABASE shopping_test TO shopping_user;
- to test that it is working run
\dt
and it should output "No relations found."
Node version 16 or up is required. If not preseent follow the following instructions
Run
npm install -g n
n 16
PATH="$PATH"
node -v
Version should be 16 and if not open another terminal or refresh your current terminal
NPM version 9 or up is required. If not preseent follow the following instructions
Run
npm install -g npm@latest
npm install
npm run lint
npm run format
Make sure you exit psql and run this command
npm install -g db-migrate
npm install -g db-migrate-pg
- Create the .env file in the home directory and add the below details:
#POSTGRES Database
POSTGRES_HOST=127.0.0.1
POSTGRES_DATABASE=shopping
POSTGRES_USER=shopping_user
POSTGRES_PASSWORD=password123
#Test Database
POSTGRES_TEST_DB=shopping_test
#environment
ENV=test
#Secrets
BCRYPT_PASSWORD=jgkt-@$^^&
SALT_ROUNDS=10
TOKEN_SECRET=fdfd.=346565jgkt-@$^^&9
Run the following command
db-migrate up
Run the following command
npm run test
Run the following command
npm run start