The Application is for the second Assignment of Udacity Full Stack Javascript
The database is running on port 5432
The Server Backend is running on port 3000
- Design Database Schema
- Use Postgres SQL
- Use Docker Container
- Data Migration
- Encode / Decode with JWT
To run the command Eslint, Prettier and Jasmine to run test senarios
Install all requirements
npm i
Unit Tests
npm run test
Run Build
npm run build
Check Style by Prettier
npm run prettier
Check code by Linter
npm run lint
The environment variable in .env file which is used for docker container
POSTGRES_HOST=127.0.0.1
POSTGRES_DB_DEV=storefront_dev
POSTGRES_TEST_DB=storefront_test
POSTGRES_USER=full_stack_user
POSTGRES_PASSWORD=password123
POSTGRES_PORT=5432
BCRYPT_PASSWORD=fullstack123
SALT_ROUNDS=10
TOKEN_SECRET=thisissecret
#ENV=dev
ENV=test
The Docker container is used to host the Postgres. In the directory, there is a docker-compose file, users can run
Check docker-compose parameter: docker-compose config
Spin up the container: docker-compose up
Stop the container: docker-compose down
We can create Docker Image for postgres without using Docker Compose: docker run -d -p 5432:5432 --name "ass2-postgres" -e POSTGRES_PASSWORD="full_stack_user" -e POSTGRES_PASSWORD="password123" postgres
Start the Container docker container start ass2-postgres
After Start the container, we can run docker ps
to see the container name
To run command on the container run docker exec -it <container name> bash
Login to postgres by psql -U postgres
with postgres is username from .env file
Run docker command to run command on the container then
Run Postgres env
su postgres
Run PSQL
psql postgres
Run following SQL queries to setup datasets in the container
Create Users and Database
CREATE USER full_stack_user WITH PASSWORD 'password123';
CREATE DATABASE storefront_dev;
CREATE DATABASE storefront_test;
After Create Database, connect to the database to grant permission
\c storefront_dev
or \c storefront_test
Grant Permission
GRANT ALL PRIVILEGES ON DATABASE storefront_dev TO full_stack_user;
GRANT ALL PRIVILEGES ON DATABASE storefront_test TO full_stack_user;
To test the database run \dt
Before run build
Run Migrate tables: npm run migrate-up
Reset database by dropping tables: npm run migrate-down
The results of the test are all PASS
The following diagram is the database Schema REQUIREMENTS file