I have started with NextJS for my front-end stack and am looking for another framework or library for the backend stack. Now, my eyes are staring at NestJS. If you are in a javascript environment most of you will choose the plain NodeJS or Express to be your back-end stack. Express is a symbol of freedom, express is a framework where you can choose any NodeJS libraries that you want to use.
Maybe is a positive if you are a single fighter or small team. When your team gets bigger or you change/add team members the pattern and documentation must be clear to be fastest on adaptation. So, your new team member can focus on the task list and build features instead of deducting how your backend works that can optimize productivity.
But, what if you are a single fighter trying to build a prototype or side project. Is there any benefit to using NestJS? Of course, there are a lot of features and patterns that will help you reduce time to think how architecture should be. You don’t have to think (i mean hard think) to make routing, etc. Wait.. I will list other benefits of using NestJS.
TypeScript
I love using TypeScript, do you? I came from a Java programmer and when trying TypeScript it is a lot easier to read the code and to follow the patterns. When using javascript, I miss static typing, object class, and interface like in Java. Then, Microsoft created Typescript to become a superset of Javascript. Hats off and thanks to the Microsoft team.
Modularity
One of the best things is modularity. Let’s say you have different teams which each of one work on different features. On API, every feature we call a service and some services have to call a data layer or module. It’s easy to attach and detach the module by using Dependency Injection.
ORM Library
‘Work on databases, ORM will help you to access and mapping the database, either you use NoSQL like MongoDB or relational databases like MySQL or PostgreSQL. Currently, there are two libraries that are commonly used. Those are TypeORM and Prisma, but to be honest I love the magic of Prisma. Prisma helps you to build data models and the relations. The syntax is more simple and readable than TypeORM.
FYI, you can directly use Prisma in your NextJS app to make it faster on prototyping. https://www.prisma.io/nextjs
Documentation
If you need documentation, you can convert the NestJS project into swagger. You can read it here..: https://docs.nestjs.com/openapi/introduction
The conclusion
Using NestJS will help you reduce the amount of time to think about the architecture and you can focus on building features. The code is readable, clean, and structurable, so hopefully can make better adaption of your team members.