This is a project which aims to create an api using both Postgresql and Express together with unit testing jasmine. We will start by setting up the environment. The package manager used here is npm, all commands will be through it, so make sure to have it installed globally on your machine.
Start by install the required packages by running npm install on the root of the project.
Install and setup Postgresql on your machine
Create a new user and grant it all privileges to the databases by running these commands in Sql shell (psql):
start with user creation: CREATE USER project_admin WITH PASSWORD projectPassword123;
then development database: CREATE DATABASE store_front;
then testing database: CREATE DATABASE store_front_test;
followed by the next two commands for granting user privileges to the database:
GRANT ALL PRIVILEGES ON DATABASE store_front TO project_admin;
GRANT ALL PRIVILEGES ON DATABASE store_front TO project_admin;
To start the application run npm run start or npm run watch which will start the app and will start looking for any changes on the code.
The ip address of the app and the port (initially the used IP address 127.0.0.1 and the used port is 3000 and for the database port it is 5432) will pop in the terminal, to change these two head to the .env file and change it to you preference.
- Note: .env variables are not supposed to be shared.
POSTGRES_HOST=127.0.0.1
PORT=3000
POSTGRES_PORT=5432
CURRENT_ENV=dev
POSTGRES_DB=store_front
POSTGRES_DB_TEST=store_front_test
POSTGRES_USER=project_admin
POSTGRES_PASSWORD=projectPassword123
BCRYPT_PASSWORD=1ts_a_5ecret_Shhh
SALT_ROUNDS=10
TOKEN_SECRET=Alb8alh12ksmsq1zzA!!
To test the app endpoints run npm run test. Test result will be on the terminal.
To test the JWT authentication use it through postman link
Creation of a new user should give a token. Copy the token head to any of the end points with other method, click on authorizarion, change it to Bearer token and paste the token there.