Should you use NestJS for your next project?

Mathias Zunino
Mathias Zunino
June 27, 2022
React
Nodejs
Should you use NestJS for your next project?

Introduction to our NestJS experience

For quite some time now, our team of engineers at VAIRIX has been working on Node.js software development projects involving different types of frameworks, which include not only web frameworks, but also different ORMs.

Examples of some of these frameworks are Koa.js, Express.js, Hapi, Fastify, TypeORM, Objection+Knex, MikrORM, Prisma, among many others.

In this article, you will learn about the advantages and disadvantages of using NestJS based on  our team’s first-hand experience.

So if you are considering NestJS for your upcoming project, this article will surely provide some insight to help inform your decision process.

Let’s dive in!

What to consider when choosing NestJS

As we mentioned above, our team has been leveraging NestJS for a while. That said, this article will focus primarily on one of our most recent projects, where our team was fully in charge of the architecture design, applying NestJS as the technology of choice.

Background and taking full ownership over a NodeJS project

Recently, one of our clients entrusted us with the planning, design and implementation of their project. And one of their non-functional requirements was that the system needed to work around the Node.js ecosystem.

The first step in our process was to discuss where we should be deploying our infrastructure and how it should be managed. And given our team’s extensive experience in working with AWS and Terraform, this was an absolute no-brainer choice for us.

Reasons and thought process behind choosing NestJS

The next step involved a conversation around the ideal frameworks for the project and how to organize the project architecture itself.

Every single one of the frameworks mentioned in our introduction were considered by our team during our discussions. But once we arrived at NestJS as an option, the debate was pretty much over.

ExpressJS versus NestJS

From our standpoint, most Node.js frameworks share the common pitfall of being un-opinionated.

This fact on its own is not necessarily a disadvantage. However, when dealing with with larger-sized projects, we could argue that all the flexibility involved in that quality could become a double-edged sword.

What differentiates NestJS is that it’s a highly opinionated framework, which to a large extent is helpful in many areas, where the developer no longer has to suffer from the mental fatigue that comes with continually thinking about things like “How do I organize this code?” or “What is the best place to put this in? The following image gives a visual representation of how in NestJS everything revolves around the modules:

NestJS modules example

Now, what happens when something does not have its own module, as is the case with Objection+Knex?

The answer seems simple: You just create said module.

But sometimes this may be more complex, since not all the modules have the same level of difficulty.

This leads us to the following considerations: “The Bad” and “The Ugly”.

The Bad and The Ugly | NestJS Disadvantages

  • Scaffolding: In NestJS, everything has a highly defined structure, so sometimes we can get lost or derailed in generating or navigating so many files.
  • Lack of clarity and confusion: Frameworks like Express or Fastify make it really easy to add a route or controller, even for a first-time user. But oh boy, when using NestJS, everything seems to work as if by magic, specially when a developer has never programmed using frameworks like Spring or .NET Core, which leads us to the next point.
  • A whole lot of magic: Similar to the previous point, magic means that something is working just because it is working. Until it stops working, that is. There are instances where doing certain things would be a thousand times simpler if done with Express rather than NestJS, and when a developer encounters these blockers, they will need someone more experienced to assist them. Someone with knowledge of dependency injection, and experience working with more seasoned frameworks like Spring.
  • Learning Curve: Mostly resulting from the previous point.
  • Feels Old: Given its resemblance to .NET Core and similar others, one might have that sense of nostalgia and feeling you’re working with something outdated. But we know this is not the case, and that it’s no more than a feeling.

The Good | NestJS Advantages

Although the above “criticism” may seem enough to scare you away from working with NestJS, we still need to consider its benefits before we skip to conclusions.

So then, what is “The Good”?

  • Extensible: Thanks to its modular architecture, NestJS is flexible and allows you to use the other existing libraries within your project (more on this below).
  • Architecture: NestJS has a project architecture that provides testing, scaling and maintenance capabilities with minimal effort.
  • Versatile: Provides an adaptable ecosystem which is developed to create all kinds of applications from the server side.
  • Progressive: NestJS makes use of JavaScript functions and implements mature solutions and design patterns in software development
  • TypeScript: ¿Need we say more? In our experience working with JavaScript, it’s been proven time and time again that cognitive complexity is proportional to project size. The bigger the project, the more time must be invested by developers in understanding how the code works: “Which parameter should I pass”; “In which order?”; “Of which type?”; “What does it return?”; and so on.
  • Documentation: NestJS encourages documentation thanks to the use of decorators.
  • Testing: Thanks to dependency injection and modularity, performing testing becomes much simpler.
  • CLI: While it isn’t a life-changing feature, the fact that NestJS includes its own CLI tool for project management and handling scaffolding is definitely a nice to have.

So should you pick NestJs for your upcoming project or not?

Well, the truth of the matter is, as usual, that it depends.

If you have to work on a small project or a proof of concept, the answer seems obvious. The work and learning curve involved in NestJS will probably take more of your time than development itself.

For projects that are large, complex, or with many “working parts”, we believe that NestJS is a viable option, and especially if your team has experience not only with Node.js, but also with other technologies and languages.

Now we want to turn it over to you: Did you find the article helpful? Reach out to our team if you’d like to discuss your upcoming project needs in more depth.

Don't miss a thing, subscribe to our monthly Newsletter!

Thanks for subscribing!
Oops! Something went wrong while submitting the form.

Introduction to Redux Toolkit + RTK Query

Redux has long been the go-to library for managing global state in React applications. However, with time, the popularity of Redux fell due to the complexity of configuring a store and also the fact that Redux requires too much boilerplate code. In this article, we will go into how Redux Toolkit solves these problems.

October 18, 2022
Read more ->
React
Redux

All you need to know about Node 13

Stay up to date with the latest Node release by reading this article on the Node 13 updates.

March 4, 2020
Read more ->
Nodejs

Contact

Ready to get started?
Use the form or give us a call to meet our team and discuss your project and business goals.
We can’t wait to meet you!

Write to us!
info@vairix.com

Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.