2
2
3
3
## Starting project
4
4
5
- Step 1 - Install project dependencies
5
+ ### Install project dependencies
6
6
7
7
``` bash
8
8
yarn install
9
9
```
10
10
11
- Step 2 - Create Postgresql database with Docker command
11
+ ### Run project prestart
12
+
13
+ ``` bash
14
+ yarn prestart
15
+ ```
16
+
17
+ This will check for the ` .env ` file and load below environment variables
18
+
19
+ ``` ts
20
+ POSTGRES_DB : undefined ;
21
+ POSTGRES_HOST : undefined ;
22
+ POSTGRES_PASSWORD : undefined ;
23
+ POSTGRES_USER : undefined ;
24
+ ```
25
+
26
+ ## Database Setup
27
+
28
+ ### Create Postgresql database with Docker command
12
29
13
30
``` bash
14
31
docker run -d \
@@ -20,49 +37,56 @@ docker run -d \
20
37
postgres
21
38
```
22
39
23
- Step 3 - Create ` Users Table ` from terminal
40
+ ### Create ` Users Table ` from terminal
24
41
25
- 1 . Get in docker container terminal
42
+ #### Get in docker container terminal
26
43
27
44
``` bash
28
45
docker exec -it {container_identifier} bash
29
46
```
30
47
31
- 2 . Login to Postgres
48
+ The {container_identifier} for Docker is the Container ID for the Docker instance
49
+ You can get it using the below command
50
+
51
+ ``` bash
52
+ docker ps
53
+ ```
54
+
55
+ #### Login to Postgres
32
56
33
57
``` bash
34
58
psql -h localhost -p 5432 -U postgres
35
59
```
36
60
37
- 3 . Go to ` node-postgres-demo `
61
+ #### Go to ` node-postgres-demo `
38
62
39
63
``` bash
40
64
\c node-postgres-demo
41
65
```
42
66
43
- 4 . Create users table
67
+ #### Create users table
44
68
45
69
``` bash
46
- CREATE TABLE users ( \
47
- id SERIAL PRIMARY KEY, \
48
- username VARCHAR(80), \
49
- email VARCHAR(255), \
50
- created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP \
70
+ CREATE TABLE users (
71
+ id SERIAL PRIMARY KEY,
72
+ username VARCHAR(80),
73
+ email VARCHAR(255),
74
+ created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP
51
75
);
52
76
```
53
77
54
- Step 4 - Create entry in ` Users table `
78
+ #### Create entry in ` Users table `
55
79
56
80
``` bash
57
- curl -H ' Content-Type: application/json' \
58
- -d
' {"username": "mateo", "email": "[email protected] "}' \
59
- -X POST \
81
+ curl -H ' Content-Type: application/json'
82
+ -d
' {"username": "mateo", "email": "[email protected] "}'
83
+ -X POST
60
84
http://localhost:5000/api/v1/users
61
85
```
62
86
63
- Step 4 - Get all users
87
+ #### Get all users
64
88
65
89
``` bash
66
- curl -H ' Content-Type: application/json' \
90
+ curl -H ' Content-Type: application/json'
67
91
http://localhost:5000/api/v1/users
68
92
```
0 commit comments