Why Nest JS is one of the best Node backend frameworks?
The Javascript community is one of the most significant development communities globally. It is not surprising that it is one of the most used languages every year.
Whether you are developing for Backend, you have many options to choose from. If you want to code Backend, the most popular choice that many developers go for is ExpressJS. You install a couple of libraries in your package.json, and now you can start creating your API or views that return HTML from the server.
So when reading the title, you will ask yourself: why do I prefer NestJS if there are many other more popular options like Express or Hapi?
Here I will give you some reasons why I have worked on some projects in NestJS and would use it again if it is a requirement to use NestJS again.
It’s NodeJS (Javascript)
We all know the advantages that NodeJS offers as a framework in the Backend, speed of execution, and the learning curve for people who come from the Frontend.
It recommends but doesn't force a specified order for work.
And it reminds me of a lot of Laravel (PHP).
Let me explain it. The folder organization looks a lot like Angular. It doesn't force you to sort your code as they put it in the tutorials. But I've found that a particular way of organizing the files is a combination of any MVC and Angular framework. Anyone coming from a Backend framework other than ExpressJS will feel more comfortable transitioning to Nest.
2
export class UsersController {3
constructor(private readonly usersService: UsersService) {}6
create(@Body() createUserDto: CreateUserDto) {7
return this.usersService.create(createUserDto);12
return this.usersService.findAll();16
findOne(@Param('id') id: string) {17
return this.usersService.findOne(+id);21
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {22
return this.usersService.update(+id, updateUserDto);26
remove(@Param('id') id: string) {27
return this.usersService.remove(+id);
Typescript support
Since 2020, developers who use Typescript have been on the rise, and I think it is due to the size of current projects and the "state" of the Frontend. There is a lot of data to connect between both sides of the development: Back and Front. It's necessary to establish specific standards so team members won’t be confused about what type of variables or functions should be used among the project. It is there that Typescript can start to shine with its autocomplete support.
When NestJS uses Typescript, the ease of writing code is greatly increased, and so are errors in data types before compilation.
2
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';6
@PrimaryGeneratedColumn()9
@Column({ length: 500 })
Documentation
What I love most about a framework are the documentation and examples that are presented on its website. Confusing documentation is one of the main reasons a junior – mid developer is not so motivated to work with a web framework, so they avoid its use. I think NestJS meets this requirement at this point. It is one of the best backend framework documentation I've seen, along with other projects like Laravel.
GraphQL, OpenAPI, ORM's support, etc.
With a section full of recipes (
https://docs.nestjs.com/recipes) with default configurations for CRUD generation, Hot reload, TypeORM, Sequelize, Swagger, Prisma and many other tools (
https://docs.nestjs.com/microservices).
Need to use GraphQL? Install a few libraries, and with less than ten lines of code, I already added support for that. Need a visual way to expose endpoints? NestJS has you covered with OpenAPI. Do you prefer Sequelize as ORM in one project but TypeORM in another because you want to see which one best suits your style? Easily switch between any of the ORMs, using the corresponding libraries and making some modifications to the configuration. Also, if you've already worked with ExpressJS, the general settings are a "piece of cake."
3
import { Module } from '@nestjs/common';4
import { GraphQLModule } from '@nestjs/graphql';7
imports: [GraphQLModule.forRoot({})],9
export class AppModule {}
I think these are the five main reasons for any new project that requires Node for the Backend. I would use NestJS without a doubt. Of course, more features make working in the Backend simple as possible, such as schedulers, WebSockets, etc. All that I leave you to discover them in its
documentation.