33
loading...
This website collects cookies to deliver better user experience
docker run --rm --name pg-docker -e POSTGRES_PASSWORD=poc-estm -d -p 5432:5432 -v $HOME/docker/volumes/postgres:/var/lib/postgresql/data postgres
--rm
is used to remove the constaine if it exists--name
is used to specify the name of the container-e
environment variables-d
in detached mode-p
port number to run on-v
volume to store the data internal to the container onpostgres
the image to pulldocker exec -it pg-docker bash
psql -h localhost -U postgres -d postgres
npm i -g @nestjs/cli
nest new <project-name>
npm install --save @nestjs/typeorm typeorm mysql2
nest generate module db
db
db.module.ts
in the above db
folder
we will need 2 other files basically interfaces and classes
db.interfaces.ts
db.errors.ts
db.module.ts
file
convict
to set up the environment variables convict26
to 36
getConnectionOptions()
this function is responsible for creating the JSON that will act as the connector in Nesttype
is the type of the database that you want to connect to it can be (PostgreSQL, Oracle, Microsoft SQL Server, SQLite, and even NoSQL databases like MongoDB) host
the the dbhost
post
is the port you want to use to connect to the DB in our case it is 5432`database
databaseNamekeepConnectionAlive
is necessary to keep a connection open with the DB23
to 29
with url:<db-url>
app.module.ts
app.module.ts
to look like aboveforRoot()
is important here it is responsible for returning a DynamicModule which will create the connection for us with the Postgres DBnpm run start:dev