Step 1 - Install project dependencies
yarn install
Step 2 - Create Postgresql database with Docker command
docker run -d \
--name node-postgres-demo \
-e POSTGRES_PASSWORD=postgres \
-e POSTGRES_USER=postgres \
-e POSTGRES_DB=node-postgres-demo \
-p 5432:5432 \
postgres
Step 3 - Create Users Table
from terminal
- Get in docker container terminal
docker exec -it {container_identifier} bash
- Login to Postgres
psql -h localhost -p 5432 -U postgres
- Go to
node-postgres-demo
\c node-postgres-demo
- Create users table
CREATE TABLE users ( \
id SERIAL PRIMARY KEY, \
username VARCHAR(80), \
email VARCHAR(255), \
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP \
);
Step 4 - Create entry in Users table
curl -H 'Content-Type: application/json' \
-d '{"username": "mateo", "email": "mateo@gmail.com"}' \
-X POST \
http://localhost:4000/api/v1/users
Step 4 - Get all users
curl -H 'Content-Type: application/json' \
http://localhost:4000/api/v1/users