Why NestJs can be a Better Choice for Node apps?

While the majority of Node developers are working on Express.js for their backend development, I must say that NestJs is a better choice for your Node apps. Why? Hmm... Because it is super amazing.

Click here for an alternate version of this article.

What is NestJs?

Kamil Mysliwiec and other open-source contributors are the real heroes behind this awesome framework. According to NestJs Official docs :

Nest (NestJS) is a framework for building efficient, scalable Node.js server-side applications. It uses progressive JavaScript, is built with and fully supports TypeScript (yet still enables developers to code in pure JavaScript) and combines elements of OOP (Object Oriented Programming), FP (Functional Programming), and FRP (Functional Reactive Programming).

NestJs uses Express.js under the hood as the default HTTP server framework which can be changed to Fastify if required. Ok, that was a small intro to NestJs, let's dive in to find the reasons behind its popularity, and why you should use it.

Why Should I use it...?

Well, Nest was smartly designed to tackle the problems of development, and at the same time, its creators were able to successfully seize the best ideas from some popular frameworks.

Uses Typescript

Are you coming from the Javascript background? I think most of us are, and you will be happy to know that you can write Nest programs in Javascript too. But I will recommend you to write it in typescript to fully utilize all the features of NestJs.

Many JS developers don't like to start working with TypeScript, but I think Typescript is one of the best things introduced in the JS world. You might be able to work fast in Javascript, Python, Ruby, or PHP due to loosely typed behavior but strictly typed Typescript reduced some silly bugs almost completely. Most of these bugs occur when you unknowingly passed the wrong data types and spend hours debugging them.

NestJs is Opinionated

Like Ruby on Rails, NestJs follows the design paradigm “convention over configuration” and is a highly opinionated framework. It means there are some guided ways to use certain tools and to code in a certain way. It helps a team to work fast where everyone knows the structure they have to follow. This helps to reduce the chances of creating a messy project structure due to unnecessary design patterns and abstractions.

Various opinions among the team members can increase the complexity and development time to choose certain tools and coding standards to be followed. New members of the team can easily learn how the code has been organized, and the tools used in an opinionated system.

Angular like architecture

Photo by Jared Rice on Unsplash

Node.js apps are built using the same language JavaScript for both back-end and front-end which reduces the overhead of learning two completely different languages. But the architecture, structure, philosophy, etc for front-end and back-end for these apps are normally different which also requires understanding the working style for both the domains.

The architecture of NestJs is inspired by the Angular framework. Module, service, controller, pipe, decorators, etc are used in NestJs to structure your codes just like Angular. A developer working on the Angular frontend can easily be deployed to the NestJs backend of the same project due to identical philosophy and concepts without wasting much time.

Domain-Driven and Performance

Modules can be created within a root module in NestJs, where every module encapsulate providers, controller, repositories, interceptors, middleware, etc. With the help of this feature, we can structure our code in logical domains for better code readability, reusability (modules), and maintainability.

NestJs uses express.js underneath by default, therefore the performance comparison between NestJs and express.js is useless. To increase the performance, you can change the underneath framework to Fastify which gives much better performance than express.js.

$ npm i --save @nestjs/platform-fastify

Command-line interface (CLI) and Testing

NestJs has its own CLI to fire up a project and scaffolding it quickly. This means modules, controllers, pipes, and middlewares can be generated very easily. It reduces the developing time of a project and increases the efficiency of a team.

NestJs CLI package comes with a default testing environment configured with the Jest framework. On generating service, controller, middleware, interceptors, etc, the CLI generates a “spec” file alongside. It contains the basic code to ease the work of the developer to write the scaffolding code for unit testing. This makes unit testing in NestJs a lot more simple.


Frameworks of Python, PHP, Java, and some other languages heavily use decorators to ease the life of a developer. Python framework Django contains many decorators such as cache the request, providing access to only login users, and many more.

NestJs is built around decorators using which you can set the request method and the endpoint, extract the session object from the request, check if the input parameter is required, and much more.

Parting Notes

Choosing the right framework for your development is not an easy task, and you must have a thorough understanding of the product you want to design. You have to choose the right tools after finding the answers to the questions like - "Is my team familiar with this technology?" or "Will my team be able to learn it quickly?" or "Is documentation available easily?".

For an Angular or Typescript developer, NestJs must be the first choice to get started. It is one of the fastest-growing frameworks in the node.js community. Till today(June/2021), NestJs has 37k+ stars on GitHub.

While NestJs is super cool and solves a lot of problems, every member of the team must be agreed to choose the specified tools, and it may consume a lot of development time. So, be careful while choosing the right tools.

That's all, folks. Have a nice day.

Post a Comment

Previous Post Next Post

Contact Form