I will start with a bold statement. Using NestJS is super cool.
The creators of it (author Kamil Myśliwiec and other open-source contributors) got inspired by other great frameworks.
They were smart enough to steal some of the best ideas floating around: Modules from Angular, Repositories, Services, Entity annotations from Spring etc.
Nest is an open source web framework which uses TypeScript.
Let’s dive in.
Why would I need it anyways…?
Well, this is easy. Because it helps you a lot!
Want to create a table for your database? Nothing easier.
Want to create a nice API so that your React app can access that you manage through your NestJS app?
Now you can further annotate your functions within that class to respond to HTTP requests (@Get, @Post etc.).
The result of these functions are then sent back to the client (Frontend Web Page, Mobile App, Smart Fridge and whatnot).
What about Express?
Everyone who starts learning Node.js will be introduced to Express, a “minimalist web framework for Node”.
It is crucial to understand that Express and NestJS are not rivals.
Express offers us a way to expose endpoints and respond to HTTP requests. That’s nice, however Nest does much more than that.
By the way, Nest is based on Express.
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
Take a look here…
This can be handy when dealing with large and complicated projects.
Certainly give it a try!
Where to go from here…
The official documentation of NestJS is really good.