# CRUD Application with TypeScript & PostgreSQL

Concepts of CRUD App

### Github Repository

[https://github.com/Labs-2021/crud-node-postgreSQL](https://github.com/Labs-2021/crud-node-postgreSQL)

Our CRUD APP Components:

1.  NodeJS
2.  ExpressJS
3.  TypeORM
4.  PostgreSQL
5.  Postgres installation with Docker

**Init Package.json**

yarn init -y

**Install Express**

yarn add express

**Install TypeScript**

yarn add typescript ts-node-dev [@types/express](http://twitter.com/types/express "Twitter profile for @types/express") -D

**Init TypeScript**

yarn tsc — init

tsconfig.json

“target”: “es2021”,

### 1\. Express

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833134451/DWD8N6WdV.jpeg)

import express from “express”;

const app = express();

app.listen(3000, ()=>console.log(“Server is running”));

### 2\. TypeORM

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833135808/qAp7EOiVW.png)

### [#](https://typeorm.io/#undefined/installation) Installation

yarn add typeorm reflect-metadata pg

1.  Install the npm package:
2.  `yarn install typeorm --save`
3.  You need to install `reflect-metadata` shim:
4.  `yarn install reflect-metadata --save`
5.  and import it somewhere in the global place of your app (for example in `app.ts`):
6.  `import "reflect-metadata";`
7.  You may need to install node typings:
8.  `npm install @types/node --save-dev`
9.  Install a database drive

*   for **PostgreSQL** or **CockroachDB**
*   `yarn install pg --save`

### [#](https://typeorm.io/#using-ormconfig/using-environment-variables) Using environment variables

Create `.env` or `ormconfig.env` in the project root (near `package.json`). It should have the following content:

```
TYPEORM_CONNECTION = mysql  
TYPEORM_HOST = localhost  
TYPEORM_USERNAME = root  
TYPEORM_PASSWORD = admin  
TYPEORM_DATABASE = test  
TYPEORM_PORT = 3000  
TYPEORM_SYNCHRONIZE = true  
TYPEORM_LOGGING = true  
TYPEORM_ENTITIES = entity/*.js,modules/**/entity/*.js
```

ist of available env variables you can set:

*   TYPEORM\_CACHE
*   TYPEORM\_CACHE\_ALWAYS\_ENABLED
*   TYPEORM\_CACHE\_DURATION
*   TYPEORM\_CACHE\_OPTIONS
*   TYPEORM\_CONNECTION
*   TYPEORM\_DATABASE
*   TYPEORM\_DEBUG
*   TYPEORM\_DRIVER\_EXTRA
*   TYPEORM\_DROP\_SCHEMA
*   TYPEORM\_ENTITIES
*   TYPEORM\_ENTITIES\_DIR
*   TYPEORM\_ENTITY\_PREFIX
*   TYPEORM\_HOST
*   TYPEORM\_LOGGER
*   TYPEORM\_LOGGING
*   TYPEORM\_MAX\_QUERY\_EXECUTION\_TIME
*   TYPEORM\_MIGRATIONS
*   TYPEORM\_MIGRATIONS\_DIR
*   TYPEORM\_MIGRATIONS\_RUN
*   TYPEORM\_MIGRATIONS\_TABLE\_NAME
*   TYPEORM\_PASSWORD
*   TYPEORM\_PORT
*   TYPEORM\_SCHEMA
*   TYPEORM\_SID
*   TYPEORM\_SUBSCRIBERS
*   TYPEORM\_SUBSCRIBERS\_DIR
*   TYPEORM\_SYNCHRONIZE
*   TYPEORM\_URL
*   TYPEORM\_USERNAME
*   TYPEORM\_UUID\_EXTENSION

.env

TYPEORM\_CONNECTION = postgres

TYPEORM\_HOST = localhost

TYPEORM\_USERNAME = admin

TYPEORM\_PASSWORD = admin

TYPEORM\_DATABASE = code\_drops\_crud

TYPEORM\_PORT = 5432

TYPEORM\_MIGRATIONS = src/database/migrations/\*.ts

TYPEORM\_MIGRATIONS\_DIR = src/database/migrations

docker run — name postgres -e POSTGRES\_PASSWORD=admin -p 5432:5432 -d postgres

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833137142/tpRUUsXzZ.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833138480/SJgDQ9PwO.png)

### BeeKeeper Studio

[**Installation | Beekeeper Studio**  
*Beekeeper Studio can be installed on Mac, Windows, and Linux desktops. Download the dmg installer file from , then drag…*docs.beekeeperstudio.io](https://docs.beekeeperstudio.io/installation/#linux-installation "https://docs.beekeeperstudio.io/installation/#linux-installation")[](https://docs.beekeeperstudio.io/installation/#linux-installation)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833140024/2W8WHftJC.jpeg)

### TypeORM Migrations

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833141692/BFEeYiNn9.png)

**Migrations Commands**

yarn typeorm migration:create -n CreateCategories

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833143482/8erOoGDzz_.png)

yarn typeorm migration:run

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833144984/EAG7dYHFTI.png)

yarn typeorm migration:revert

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833146582/IKnW-_xNq.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833147976/c7XZaALqQ.png)

### Migration Videos

yarn typeorm migration:create -n CreateVideos

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833149227/P2F51U7Et.png)

### UUID

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833150611/rsJuy64Hi.png)

yarn add uuid

yarn add @types/uuid -D

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833152649/HsBN92dZl.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833154396/1geayzUbi.png)

Insomnia CRUD Github

[https://github.com/Labs-2021/crud-node-postgreSQL/blob/main/.insomnia/Workspace/wrk\_4b5e4a867e9c4195b058da96bfa7571b.yml](https://github.com/Labs-2021/crud-node-postgreSQL/blob/main/.insomnia/Workspace/wrk_4b5e4a867e9c4195b058da96bfa7571b.yml)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833155755/fH_3nj_la.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833157110/geM4keCUX.png)

### Create Video

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833158436/IOjyPuGwh.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833159775/LnVAuBlhn.png)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833161220/VL_JoWVhK1.png)

### 5\. Postgres installation with Docker

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833162614/-A-BJj-o4.jpeg)

*   [https://hub.docker.com/\_/postgres](https://hub.docker.com/_/postgres)

docker pull postgres

docker run --name postgresql -e POSTGRES\_PASSWORD=admin -p 5432:5432 -d postgres

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1662833163944/j-l6J9l4U.png)

❯ docker run -d --name postgresql-dev -e POSTGRESQL\_USERNAME=postgres -e POSTGRESQL\_PASSWORD=docker -e POSTGRESQL\_DATABASE=gobarber -p 5432:5432  bitnami/postgresql:latest
