Photo by Unsplash

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.
1
# Installing NestJS globally
2
npm i -g @nestjs/cli
3
# Creating a new project
4
nest new project-name

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.
1
@Controller('users')
2
export class UsersController {
3
constructor(private readonly usersService: UsersService) {}
4
5
@Post()
6
create(@Body() createUserDto: CreateUserDto) {
7
return this.usersService.create(createUserDto);
8
}
9
10
@Get()
11
findAll() {
12
return this.usersService.findAll();
13
}
14
15
@Get(':id')
16
findOne(@Param('id') id: string) {
17
return this.usersService.findOne(+id);
18
}
19
20
@Patch(':id')
21
update(@Param('id') id: string, @Body() updateUserDto: UpdateUserDto) {
22
return this.usersService.update(+id, updateUserDto);
23
}
24
25
@Delete(':id')
26
remove(@Param('id') id: string) {
27
return this.usersService.remove(+id);
28
}
29
}

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.
1
// A DB model using TypeORM defined with the power of Typescript
2
import { Entity, Column, PrimaryGeneratedColumn } from 'typeorm';
3
4
@Entity()
5
export class Photo {
6
@PrimaryGeneratedColumn()
7
id: number;
8
9
@Column({ length: 500 })
10
name: string;
11
12
@Column('text')
13
description: string;
14
15
@Column()
16
filename: string;
17
18
@Column('int')
19
views: number;
20
21
@Column()
22
isPublished: boolean;
23
}

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."
1
// Adding support for GraphQL with a single line
2
// NPM install of packages is required though
3
import { Module } from '@nestjs/common';
4
import { GraphQLModule } from '@nestjs/graphql';
5
6
@Module({
7
imports: [GraphQLModule.forRoot({})],
8
})
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.
My posts are not AI generated, they might be only AI corrected. The first draft is always my creation

Author

Written by Helmer Davila