This may surprise you in a discussion about server-side development, but I promise you it’s relevant: to understand NestJs, you need to understand the differences between React and Angular.
I’ve spoken about these at length: React provides flexibility and freedom, whereas Angular provides stability and reliability. The client-side is driven by user experience, so it makes sense that front-end developers have been attracted to the freedom and agility that React provides.
But what about on the server? What is the best paradigm to apply there? And that is the perfect opportunity to talk about…
What is Nest JS? And why is it worth learning?
Because you see, I can’t think of a more appropriate way of explaining what NestJS is than saying: it’s an Angular-inspired server-side framework.
NestJS is a Typescript framework for building efficient, scalable server-side applications. And the Angular inspiration is visible wherever you look. In the way things are organised, in the way you code, in the way you inject dependencies. In the choice of Typescript as the core language. If (like me) you’re familiar with Angular, you’ll feel right at home with NestJS.
What does this imply?
If front-end development is driven by user experience, back-end development is all about data and logic. And here, Angular’s structure makes sense. On the server, you don’t want flexibility; you want security. Angular’s opinionated nature is Nest JS’s main strength.
Let’s dive into its features.
The features of NestJS
NestJS has a modular architecture that helps organise your code. Like Angular, you structure your code into independent modules that hold components. You can define pipes that allow you to change data. And (obviously) Nest has controllers.
For each of these, Nest JS follows in Angular’s footsteps by using decorators to define the different behaviours.
Like Angular, NestJS provides extensive features out of the box: task scheduling, queues, logging, cookies, and validation, to name a few…
In short, everything you expect a full-fledged backend framework to have. It even has built-in support for WebSockets allowing you to set up your own real-time chats or multiplayer games.
Nest JS’s strengths and weaknesses
But how does NestJS stack up against other alternatives? Compared to other Node.js frameworks like Express.js or Koa.js, NestJS has more features, is more opinionated (Angular, again) and is more robust.
And this really feels like revisiting the React versus Angular comparison all over again: Like React, Express and Koa are minimalistic and require additional libraries for features. Like Angular, NestJS provides a comprehensive solution, reducing the need to hunt for external libraries.
An additional strength is Nest’s similarities with Angular: if you know the one, you’ll feel right at home with the other.
That being said, NestJS’s strengths are also its shortcomings. NestJS is opinionated, so its learning curve is steeper than simpler frameworks. And the wealth of features might be overkill for smaller projects.
But if you do want or need to learn Nest JS, I recommend you read the principles of Angular, and do the Tour of Heroes tutorial.
Why learn NestJS ?
So, why should you, as a developer, learn NestJS? In a sense, the steep learning curve I mentioned is precisely the reason why Nest JS is worth learning.
Because what you’re learning is not a specific syntax. You’re learning best practices of back-end development embodied into a framework. It’s worth learning those… even if you later develop with a different framework or language.
Or, to phrase things differently: When you’re investing time learning Nest JS, you’re actually investing time in yourself.