Skip to content

mateogalic112/node-postgres-demo

Repository files navigation

Node.js with Postgresql DEMO

Starting project

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

  1. Get in docker container terminal
docker exec -it {container_identifier} bash
  1. Login to Postgres
psql -h localhost -p 5432 -U postgres
  1. Go to node-postgres-demo
\c node-postgres-demo
  1. 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

About

Connect Node.js with Postgresql database DEMO

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published