Build a Nest.js App With TypeORM and Postgres | by Kevin Vogel | Feb, 2022

Create scalable apps with Nest.js & TypeORM

It’s required to have a fundamental understanding of Node.js, TypeScript, and PostgreSQL which you may have put in domestically in your machine. I’ll select Visual Studio Code as my code editor. You need to use no matter you like.

First, we have to create our PostgreSQL database. I do know, everyone handles that in another way, some folks use a GUI, however we going to make use of our terminal. Once more, it is advisable to have PostgreSQL put in in your machine. In case you have PostgreSQL put in, the next 4 instructions will run on Linux, Mac, and Home windows machines.

$ psql postgres
$ CREATE DATABASE nest_api;
$ l
$ q
  • CREATE DATABASE nest_api; creating the database we’d like
  • l record all databases
  • q CLI exit

Let’s proceed with Nest.js! We’re going to set up the Nest.js CLI, so open the terminal of your alternative and sort:

$ npm i -g @nestjs/cli
$ nest new nest-postgres -p npm
$ cd nest-postgres
$ code .
$ git add .
$ git commit -m "chore(): init nest.js"
$ npm i @nestjs/config @nestjs/typeorm typeorm pg class-validator class-transformer
$ npm i -D @sorts/node
$ mkdir src/shared
$ mkdir src/shared/typeorm
$ mkdir src/frequent
$ mkdir src/frequent/envs
$ mkdir src/frequent/helper
$ contact src/shared/typeorm/typeorm.service.ts
$ contact src/frequent/envs/.env
$ contact src/frequent/envs/improvement.env
$ contact src/frequent/helper/env.helper.ts
nest-cli.json
nest-cli.json
src/frequent/helper/env.helper.ts
src/comon/envs/.env
src/comon/envs/improvement.env
src/app.module.ts
src/app.module.ts
src/shared/typeorm/typeorm.service.ts
src/app.module.ts
src/app.module.ts
$ npm run begin:dev
$ nest g mo api
$ nest g mo api/person && nest g co api/person
--no-spec && nest g s api/person --no-spec
$ contact src/api/person/person.entity.ts
$ contact src/api/person/person.dto.ts
src/api/person/person.entity.ts
src/api/person/person.dto.ts
src/api/person/person.module.ts
src/api/person/person.module.ts
src/api/person/person.service.ts
src/api/person/person.service.ts
src/api/person/person.controller.ts
src/api/person/person.controller.ts
$ npm run begin:dev
$ curl -X POST http://localhost:3000/person -H "Content material-Sort: utility/json" -d '"title": "Elon Musk", "e mail": "elon@gmail.com"'Server Response:"title":"Elon Musk","e mail":"elon@gmail.com","id":1,"isDeleted":false,"createdAt":"2022-02-18T14:12:13.672Z","updatedAt":"2022-02-18T14:12:13.672Z"

More Posts