As a beginner why we must choose the Nest js framework for Node js implementation for the backend…

Wathsala Rasanjalee Ganewatta
5 min readMay 31, 2021

I am new to node js with implementing backend service. But I have experience with java. I have done some tutorials of the nest js framework. And that is a well-documented framework. Every beginner easily catches up with the nest js because of its clear documentation. From my lower experience, I can gather a lot of knowledge within a limited time period like one month to do my new project. Nest js has all the features we are using to create an application. when I comparing java with node js I think node can easily be done with nest js. Java is older and it used for many years. But nowadays most developers go with node js, because of its speed.

I have done my new project with angular and also I have work with angular before. angular go with typescript and also nest js go with typescript. So if we use the same language in both backend and frontend it's easy to interact with both sides.

if we consider it with java for the frontend java has java swing it has a little bit different.

Using nest js easily integrate with common technologies like typeORM, mongoose, graphQL, Logging, caching, WebSockets, microservices. For all of these nest js has documentation so it is very easy for beginners.

Nest js has a specific architecture module, services (provider), controllers.

Modules

Which typescript file is decorated using “@Module” called a module. In that provides metadata that makes use of to organize the application structure. This typescript file is used to organize the code and split features into logical reusable units.

Providers

This is also known as services. Providers can be created and injected into controllers or other providers. In that file always write the logic.

Controllers

This is responsible for handling incoming requests from the client-side and also returning the appropriate response to the client-side.

For Example:

import { Body, Controller, Get, HttpException, Post} from ‘@nestjs/common’;import {CustomerCreateDto} from ‘./customerCreate.dto’import { UserService } from ‘src/user/user.service’;@Controller(‘user’)export class UserController {constructor(private userService: UserService){}@Get()async getAllUsers():Promise<User[]>{return this.userService.getAllUsers();}@Post()async createUser(@Body() userCreateDto:UserCreateDto){const user = await this.userService.createUser(userCreateDto);if(!user){return new HttpException(“Not created”,204);}return user;}}

There get a request to get all users and post a request to create users. From client-side call that endpoints then this controller handles that request and returns the appropriate response for the client-side.

What is NestJS?

  • NestJS is an open-source
  • NestJS is an extensible
  • NestJS is a versatile
  • Progressive Node.js framework for creating compelling and demanding backend systems.
  • It is currently the fastest-growing Node.js framework in TypeScript.

Node js can use both sides of a development's backend and frontend. So Node js is the fastest-growing programming language.

  • Nest js applications are easy to maintain and highly scalable frameworks.
  • Nest js methods are asynchronous. Those asynchronous methods can handle in two ways

Using async-await:

async getAllFeedbacks(){
return await this.feedbackRepository.findAll();
}

Using Promises:

async getAllFeedbacks():Peomise<Feedback[]>{const feedbacks = await this.feedbackRepository.findAll();

return feedbacks;
}

NestJs is Opinionated Frameworks but ExpressJs is an Un-Opinionated framework.

Opinionated Frameworks:

Opinionated Framework has there own pros and cons,

Pros:

  • Best practices are defined upfront and are usually tried and true.
  • The framework designers have built a “happy pat” making development easier and faster.
  • Usually includes lots of functionality ou of the box.

Cons:

  • If you must do something unusual that is outside the scope of the framework it will require extra work.
  • Usually larger framework size
  • May require optimization/cashing in order to archive required performance.

Un-opinionated Frameworks

The un-opinionated framework has there own pros and cons:

Pros:

  • You are free to define your own architecture, structure, etc.
  • Smaller and more lightweight footprint as you only have the core package included.
  • Usually better performance out-of-the-box due to smaller footprint and number of libraries.

Cons:

  • Requires solid software engineering skills to create, manage, and maintain the architecture and structure.
  • More choices to make regarding liberties to install, best practices to choose from, etc.

When we choose a framework we have to consider some factors those are,

  • Project type (standard or highly customized)
  • Development team experience
  • time frame
  • Scalability requirements
  • Tech stack requirements

Conclusion

There are a lot of frameworks to work with node js. But Nestjs one of the most rapidly growing Nodejs frameworks. If the developer is familiar with Angular and typescript I think nestJS is the most suitable framework for backend developments. There are lot of references to know about nestJS and learn about this framework.

--

--