DEV Community

Dilum Darshana
Dilum Darshana

Posted on β€’ Edited on

1

Why NestJS Became My favourite Node.js Framework (After Years of Express.js)

After spending nearly a decade building backend applications with Express.js, I thought I had everything I needed. Express is fast, easy to understand, and can build just about anything.

But as my projects grew larger, so did the complexity. I started facing challenges like maintaining a clean folder structure, managing dependency injection manually, code complexity and struggling with testability.

That is when I gave NestJS a serious try β€” and honestly, it felt like switching from manual to automatic. Today, it’s my go-to framework for scalable Node.js applications. Here’s why.

🟒 What is NestJS ?

A progressive (start with minimal) Node.js framework built with awesome TypeScript support based on Express or Fastify. It uses decorators heavily for reusability. OOP (Object Oriented Programming) or FP (Functional Programming) as needed. Would be ideal for medium and large scale projects

🟒 My Journey with Express.js

Express was the most convenient framework at the time I started my development career. It was easy to understand and flexible enough to develop almost every features what I needed.

After sometimes, when the projects are become larger and larger, it was hard to keep the consistency of the codebase. And, testing them as a module was a bit tricky. I had to create my own boilerplate with the specific folder structure.

Here is the one I created some times back: My Express based Boilerplate

🟒 Why I Switched to NestJS

There is few reasons I prefer NestJS over Express.

  • Well architected boilerplate with minimum features
  • It is already tested well
  • Can scale easily
  • Native Typescript support
  • Required extensions mostly provided by NestJS team itself (eg. JWT, Passport, Graphql, Cors, etc...)

🟒 Key Features That Sold Me on NestJS

  • Dependency injection
  • Modular pattern
  • Built-in features, like, Guards, Interceptors, Middlewares, Pipes
  • Typescript native support (Heavy with Decorators)
  • Easy expanding with external modules (Eg. Cors, JWT, Config, etc...)
  • Well structured folder structure
    Folder Structure

  • Easy routes with simple controllers
    Sample Controller

  • Support for microservices (I still not tried out this)

  • API documentation with few lines of codes (Swagger integration)

🟒 Drawbacks of NestJS (Yes, It might Has Some)

I still did not encountered significant drawbacks. It might be quite overhead for use NestJS for very small projects. And, obviously, there is a learning curve when switch from Express.js

🟒 Should You Switch?

Im my opinion, there are several factors need to consider behind it. If you have significant scalable app to be implemented, you have a good knowledge of TypeScript and if your app going to be type of microservices, then better option would be use NestJS

🟒 Final Thoughts

Switching from Express.js to NestJS was one of the best decisions I’ve made for building scalable backend apps. Still Express.js would be a good choice specially for small projects and MVPs.

🎯 If you haven’t tried it yet, I highly recommend giving it a shot!

NestJS Docs

🀝 I will write an another post on NestJS internals sooner Check Here

Cheers... Happy coding!!!

Top comments (0)

πŸ‘‹ Kindness is contagious

Please leave a ❀️ or a friendly comment on this post if you found it helpful!

Okay