This repo contains a storefront backend api that connects to the database for communication with the frontend. The API needs are stated in REQUIREMENTS.md
This application makes use of the following libraries:
- Postgres for the database
- Node/Express for the application logic
- dotenv from npm for managing environment variables
- db-migrate from npm for migrations
- jsonwebtoken from npm for working with JWTs
- jasmine from npm for testing
-
Clone the project here on github
git clone https://github.com/edwinmambo/storefront-backend.git
-
- Have docker installed
#check if docker and docker compose are installed docker version docker compose version
- I use
yarn
as the package manager - create an
.env
in file with the following variables:
POSTGRES_HOST POSTGRES_DB POSTGRES_TEST_DB POSTGRES_USER POSTGRES_PASSWORD ENV BCRYPT_PASSWORD SALT_ROUNDS TOKEN_SECRET
The default values I use are the following:
- host: 127.0.0.1
- db: full_stack_dev
- test db: full_stack_dev_test
- user: full_stack_user
- password: password123
- env: dev
NOTE: bcrypt password, salt rounds and token secret are of your own choosing.
-
npm install --global yarn yarn
-
For both the dev and test environments:
Run the container from
docker-compose.yml
# runs on port 5432 docker compose up
Connect to the container and run the following to setup the database (Use values in your
.env
file):Create a user
CREATE USER full_stack_user WITH PASSWORD 'Password123';
Create Databases
CREATE DATABASE full_stack_dev; CREATE DATABASE full_stack_dev_test;
Grant all privileges on both databases to user
GRANT ALL PRIVILEGES ON DATABASE full_stack_dev TO full_stack_user; GRANT ALL PRIVILEGES ON DATABASE full_stack_dev_test TO full_stack_user;
-
# In a separate terminal yarn watch
-
yarn test
The server will run on localhost:3000/
or 0.0.0.0:3000
where the api will be under the specific endpoint as in REQUIREMENTS.md
Products: http:localhost:3000/products
Users: http:localhost:3000/users
Orders: http:localhost:3000/orders