Amitav Roy

Blog on web and travel

Nest.js - a node based framework and why it is a good choice

Posted on 26 Jan 2023 by Amitav Roy

Nest.js - a node based framework and why it is a good choice

Nest.js is a Node framework which gives you the power to write modular and scale-able code. And, while there are many Node based frameworks out there, it solves one big problem - Architecture.

As a software developer, we want to build maintainable and scale-able apps keeping the development process simple and face-paced. And, as one of the most dominant technology in the market, I was on a question to find one framework on which I can invest my time.

Out of the big list of frameworks out there for Node, Nest.js was one which attracted my company Focalworks Solutions a lot and when I worked on it, the feeling resonated with me as well (for some time, I even tried Sails.js and Adonis.js but came back to Nest.js).

With over 53.8K starts, it is one of the fastest-growing Node.js frameworks. And, if you go to the Nest.js website and look at who is using this framework, you will find some big brand names like Adidas, Decathalon, Autodesk.

Nest.js at the heart is built with the idea of solving one big problem - Architecture. I say so because it provides an application architecture which allows developers to create highly scalable, loosely coupled apps which are easy to maintain as well.

Some good things about Nest.js

Easy to learn

Developers coming from Angular background will find it very easy to pick up. For example, you code will be divided into modules. Each module will have a .module.ts file which will define the different services it has, the controllers and many other details.

Those who don’t know Angular like me can refer to the very nicely done documentation which has great explanation and example codes as well. If you are a visual learner like me, then you can also go through this Youtube playlist on Nest.js which has 32 videos going through every details of Nest.js and how to get strated.

Modular code

The framework is structure in a way that writing module code is easy. You will feel like breaking your apps requirements into smaller modules which can be very loosely coupled. Each module can focus on solving one part of the big puzzle. And, it’s easy to make it very loosely coupled and hence reuseability of that becomes easier.

It is also very easy to develop using a Microservice pattern because Nest.js can connect not through the ad port of the apache server but internally through a TCP port. Socket-based connections are possible as well for microservices.

This is a huge advantages because multiple teams can wok on different areas of a large proeject.

A great developer experience (DX)

Nest.js is built with Typescript, so the overall development experience is great. The type system will help you understand errors faster and also it helps you write better code.

Some developers like me who haven’t worked with the decorator patter a lot might feel a little incomprehensible at first, but you will get use to it quickly.

Nest.js also has a great integration with Swagger which allows you to publish your APIs as working Swagger documentation. It is not only a great help for Opensource projects, but also helps in development team as documentation of your API.

Also, apart from just creating REST APIs, you have the ability to work with GraphQL as well.

Dependency injection (DI)

Contains a built-in DI container (Dependency Injection) which makes applications modular and more efficient. Thanks to TypeScript capabilities, it's extremely easy to manage dependencies because they are resolved just by type.

You can inject services inside controllers and do other stuff quite easily without worrying about managing the instances.

The powerful CLI

It has a CLI which is helpful in many common tasks like creating modules, adding services etc. A powerful CLI does help a lot with easy development.

Resources for learning Nest.js

  1. Nest.js documentation is going to be the first thing that you should look at.
  2. A Youtube video series on Nest.js where I have shown how to build an app and some core concepts of the framework
  3. You can also look at the channel from Marius Espejo where you can find a lot of concepts of Nest.js


So, as you can see from the above points, there are more than couple of good points why Nest.js can be the next framework that you would like to choose for your project.

Whether it is starting out with a new idea or converting a legacy application into a modern stack using Microservice architecture, Nest.js can be a great choice.

So, if you have already developed projects using Nest.js and want to share your thoughts, reach out to me on my twitter account @amitavroy7 and let us discuss.