Storefront API using node js connected to a Postgres database.
A storefront backend to support connecting to a database and allow making changes to the database. the database has 4 tables:
- users
- products
- orders
- order_products
The 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
- We use a docker container for the postgreSQL database. To create the container and setup the
shopping
database, run thedocker-compose up --detach
command in the terminal. - We create tables by running the
npx db-migrate up
command. - To start the server run the
npm run start
command from the terminal. The backend runs on port 3000, and the database on port 5432.
- Create all tables:
npx db-migrate up
- Drop one table at a time:
npx db-migrate up
- Drop all tables:
npx db-migrate reset
- prettier:
npm run prettier
- start:
npm run start
- watch:
npm run watch
- test:
npm run test
- To connect to the container we run
docker exec -i -t storefront-backend_postgres_1 /bin/bash
wherestorefront-backend_postgres_1
is the container name. - To connect to the postgreSQL database we run the following command in the terminal:
psql shopping -h localhost -U shopping_user postgres
whereshopping
is thePOSTGRES_DB
andshopping_user
is thePOSTGRES_USER
. - To create the testing database run the SQL command
CREATE DATABASE shopping_test
whereshopping_test
is the testing database.
POSTGRES_HOST=127.0.0.1
POSTGRES_DB=shopping
POSTGRES_TEST_DB=shopping_test
POSTGRES_USER=shopping_user
POSTGRES_PASSWORD=password123
ENV=dev
BCRYPT_PASSWORD=secret
SALT_ROUNDS=10
TOKEN_SECRET=secrettoken
- PostgreSQL โ Data Types
- Default Values
- Routing
- Docker PostgreSQL Tutorial with Persistent Data
- docker-compose up
- frequent-docker-commands.sh
- Shorouk Elkhateeb