Rabu, 17 Maret 2021

NestJS is Great, Why?

I have started with NextJS for my front-end stack and looking for another framework or library for the backend stack. Now, my eyes staring at NestJS. If you on javascript environment most of you will choose the plain NodeJS or Express to be your back-end stack. Express is symbol of freedom, express is a framework that you can choose any NodeJS libraries that you want to used. 

Maybe is a positive if you are a single fighter or small team. When your team getting bigger or you change/add team member the pattern and docs are must be clear to be fastest on adaptation. So, your new team member can focus on task list instead of deducting how is your backend works (optimize the productivity)

When I looking at NestJS, all the good things are in it. The code are readable, clean, and structurable. Almost the same when I try Angular 5 (if you are Java programmer is easy to read and code the Angular 5 app). If you need a great documentation it's easy to convert it into Swagger.

Let's try to install NestJS

First, make a directory folder for your project. Open your terminal and route into the folder. After that type the code below to init/create NestJS project.

npm i -g @nestjs/cli
nest new your-project-name

After finish, run the project with typing "npm run start" or "npm run start:dev" if you want to using hot reload feature. Now, access the project typing "localhost:3000" on your browser. If you want to change the port, you can open and edit the "main.ts" file.

For Swagger, you can type code below 

npm install --save @nestjs/swagger swagger-ui-express

Database

For database abstraction, you can use Prisma or TypeORM. If you want to know more about them, you can read it on this link What the difference Prisma and TypeORM. For this case, I choose to use the Prisma because it easy, simple, and readable syntax. But for you. you decided by yourself. 

  1. Installation: npm install prisma --save-dev
  2. After install successful, type "npx prisma" on terminal it will give you information about Prisma command.
  3. Then type "npx prisma init", it will create .env file to setup your database. 
  4. More information you can read it here "How to setup Prisma on NestJS". 





Related Articles

0 komentar:

Posting Komentar