What’s new?

There is a lot of new things that came up with Nest 5. I can’t list all of them, it would take forever. Nevertheless, I’ll a share a couple of changes that makes me excited about this release. You could find them all in the official documentation.

Performance

We place great emphasis on performance and portability. That’s why Nest 5 is loosely coupled from the underlying web library. Obviously, express is still being used as a default provider, but you’re able to adapt any other package once you fulfil an interface. This capability helps us to achieve a significant performance boosts by creating a built-in fastify adapter.

The fastify adapter is even ~70% faster than express one (read more).

With FastifyAdapter the number of processed requests per second is on average ~70% higher than with ExpressAdapter . In addition, we are able to ship more integrations in the near future with other HTTP libraries, for example, with the polka server.

Extremely fast rebuilds

The blazing fast server-side development helps you quickly and easily experiment with your code.

~1 second to reload your app (read more).

Thanks to the webpack hot reload feature, your application will apply changes even within 1–2 seconds, reducing amount of time spent on the compilation to an absolute minimum.

New documentation

The previous version of the documentation was very poor in terms of valuable content. A bunch of parts has been missed, examples were small and inconsistent.

Together with Nest 5 release, you’ll find more detailed code snippets, in-depth explanations, and clearer design. Visit the documentation today and let us know what you think.

Angular-style consistency

We aren’t a framework for Angular people. Nest syntax is heavily inspired by the Angular design though because it’s well crafted and ideally suited to scalable systems. Besides, Nest should be easy to absorb for people who also come from other languages and various platforms.

But still, the Angular background is definitely a huge advantage. The same concepts and similar design patterns make the learning curve incredibly short. Additionally, in order to reduce inconsistencies, in Nest 5 a few decorators have been replaced by @Injectable() (read more). Furthermore, the module definition has been adjusted as well.

The module definition is almost the same as in Angular.

Another big advantage is an ability to set up global filters, interceptors, pipes, and guards directly inside the module providers , using custom providers feature.

The global interceptor registered inside the module definition.

CLI

The Nest CLI makes it easy to scaffold an application that already works, right out of the box, and improves your developer productivity due to generate command. This tool takes advantage of the powerful angular schematics, giving you full extensibility and reusability.

The CLI overview (new project generation process).

Besides, the generate command will automatically update your code, for example, put newly created service into providers array of the specified module.

The generate command automatically updates your code.

Less opinionated

Previously, the dependency injection has been disabled for both filters and pipes. On the other hand, it was impossible to manually instantiate interceptors and guards. In the new version, either approach is always fine. You decide which method to follow depending on the functionality requirements. When you want your AuthGuard to stay loosely coupled from any module, create an instance immediately.

Otherwise, pass a class and Nest will handle the instantiation responsibility for you.

Moreover, changes didn’t omit guards, interceptors, and filters. The API has changed in order to make them even more flexible and cohesive. For example, in Nest 4 you were able to solely access request argument inside the guard’s canActivate() method. Now you might pick up any argument effortlessly, using either ExecutionContext or ArgumentsHost (depending on the evaluation context).

Robust microservices

The @nestjs/microservices package has been completely rewritten. It brings a couple of new transporters (for example gRPC) and several improvements to the existing ones, giving you a strong platform to create a different kinds of microservices on top of Node.js. Also, for these services that don’t fit a request-response paradigm, you might make use of the execution context feature.

An example of the gRPC microservice.

Migration from Nest 4

In order to migrate your existing project, follow the guidelines that are available here. Besides, make sure to get rid of all deprecation messages that may appear in your console.