yarn install
Rename the file .env.example
to .env
This step is important to run before running the prestart
command
yarn prestart
This will check for the .env
file located at the project root level and load below environment variables
POSTGRES_DB: undefined;
POSTGRES_HOST: undefined;
POSTGRES_PASSWORD: undefined;
POSTGRES_USER: undefined;
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
docker exec -it {container_identifier} bash
The {container_identifier} for Docker is the Container ID for the Docker instance You can get it using the below command
docker ps
psql -h localhost -p 5432 -U postgres
\c node-postgres-demo
CREATE TABLE users (
id SERIAL PRIMARY KEY,
username VARCHAR(80),
email VARCHAR(255),
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
);
$curl -H 'Content-Type: application/json' \
-d '{"username": "mateo", "email": "[email protected]"}' \
-X POST \
http://localhost:5000/api/v1/users
We can send JSON data using POST with curl using the --json
option.
$curl --json '{"username": "mateo", "email": "[email protected]"}' http://localhost:5000/api/v1/users
$curl -H 'Content-Type: application/json' \
http://localhost:5000/api/v1/users