What Is Nest.js?
Nest provides a level of abstraction above these common Node.js frameworks (Express/Fastify), but also exposes their APIs directly to the developer. This gives developers the freedom to use the myriad of third-party modules which are available for the underlying platform.
What can Nest do? Amaze me!
- Interact with your database easily in an abstracted manner. You just create and annotate classes with decorators. This is called Object Relational Mapping (“ORM” might sound more familiar)
- Create service layer classes easily to handle the business logic of your application. Then, inject (read: “use”) these services in other services with the help of NestJS’ dependency injection
- Create so called “Controllers”, which can easily respond to HTTP requests. This is your main way to interact with the clients of your Nest app (React? Vue? Mobile app? Another service? Anything.)
- Secure the endpoints you create with Controllers. Nest makes it easy to guard the API of your app, so only (for example) logged in users can access them (be it basic auth., JWT etc.)
- Create microservices with Nest. Cool.
- Build a GraphQL interface easily
- Integrate message queues into your app (maybe you need to do some asynchronous data processing?)
- …and much more
Why Nest JS?
Let me first begin by listing the fundamentals of any backend system, and my review will be based on weather Nest JS covers them or not.
Back-end fundamental areas:
- Server architecture
- Database administration
- Data transportation
- Integrations and third-party libraries (tools) support.
Next, I will depend on the following criteria to measure the pros and cons
- Nest JS is a highly opinionated framework, the architecture paths are already built, and the developers follow the provided structure guidelines (The architecture is heavily inspired by Angular's solid structure).
- In my opinion this makes it easier for the team to understand each others code and find things quickly.
- There are two important aspects of software performance: responsiveness and scalability,
- Nest JS is perfect to handle these aspects.
- Nest JS offers compatibility with other libraries, such as Fastify or Express.js out of the box.
Their official documentation covers all the backend aspects I've mentioned earlier, using the latest trend technologies and best practices.
You can use any testing framework that you like, as Nest JS doesn't force any specific tooling, but it provides integration with Jest and Supertest out-of-the-box.
Integrations, Libraries, Security
- All Node JS packages and integrations are available.
- Many aspects are ready out-of-the-box, such as: Database (TypeORM), Data Validation, Caching, Task Scheduling, Logging, Cookies, File Upload, Server-Sent Events, Authentication, Authorization, Encryption, Hashing, Helmet, CORS, CSRF, Limiters, GraphQL, WebSockets, Microservices, Redis, MQTT, Kafka and more
- NestJS adopted both TypeScript and Angular features.
- NestJS uses TypeORM which gives leverage to connect with SQL and NoSQL databases.
- Since NestJs is an Abstraction over the NodeJS. So we can use NodeJS libraries
- NestJS surrounds your route handler body with try catch blocks, and it binds error-handling middleware.
If you are a Node JS and TypeScript fan then definitely you should keep Nest JS in your mind for your next project.
And if you are familiar with .NET Core structure and core concepts, you will definitely fall in love with Nest JS.