DEV Community

Amanpreet Singh
Amanpreet Singh

Posted on • Originally published at blog.amanpreet.dev on

Unpacking the Latest Features of NestJS v10

Unpacking the Latest Features of NestJS v10

Introduction

NestJS v10 is here! This progressive Node.js framework offers efficient, reliable, and scalable server-side app building.

As per the StackOverflow Developer survey, NestJS is one of the top 10 most popular backend frameworks in the world. Check the survey results here.

It has more than 58k Github stars on its repository.

What's New?

Recently NestJS has officially released v10 for building efficient and enterprise-grade, server-side applications. Let's deep dive and see what are the new features of the new version.

SWC Integration

SWC stands for Speedy Web Compiler. It is an extensible Rust-based platform that can be used for both compilation and bundling. To speed up your development process, using SWC with NestJs CLI is a great way.

Installation of required packages is as follows:

$ npm install --save-dev @swc/cli @swc/core

Enter fullscreen mode Exit fullscreen mode

You can now use SWC with NestJs CLI as follows:

$ nest start -b swc
# or
$ nest start --builder swc

Enter fullscreen mode Exit fullscreen mode

Another way to use SWC by default is via nest-cli.json file, as mentioned below:

{
    "compilerOptions": {
        "builder": "swc"
    }
}

Enter fullscreen mode Exit fullscreen mode

By default, SWC does not perform any type-checking itself, so to enable this option we need to use --type-check flag, as mentioned below:

$ nest start -b swc --type-check
# or
$ nest start --builder swc --type-check

Enter fullscreen mode Exit fullscreen mode

💡 SWC is approximately 20 times faster than the default TypeScript compiler.

Redis Wildcard Subscriptions

Added support for Redis wildcard subscriptions. This feature allows one to subscribe to all messages that match a given pattern.

To start using Redis-based microservices, install the required packages as follows:

$ npm install ioredis

Enter fullscreen mode Exit fullscreen mode

By default wildcard subscription is false, to enable the wildcard subscription

const app = await NestFactory.createMicroservice(AppModule, {
  transport: Transport.REDIS,
  options: {
    host: 'localhost',
    port: 6379,
    wildcard: true, // this is the new option available
  },
});

Enter fullscreen mode Exit fullscreen mode

With wildcards enabled, we can use glob-type patterns in our subscriptions, such as:

  • ne?tjs subscribes to nestjs, nextjs and nuxtjs

  • ne*tjs subscribes to netjs and neetjs

What's Improved or Changed?

Together with new changes, there are some improvements in the latest v10 of NestJS.

Changes to Cache Module

Caching is a great and simple technique to improve your app's performance.

The CacheModule is now available as a standalone package @nestjs/cache-manager. Earlier this package was available under @nestjs/common

To install the required packages:

$ npm install @nestjs/cache-manager cache-manager

Enter fullscreen mode Exit fullscreen mode

Overriding Modules in tests

Overriding of modules in tests has been introduced in v10. This feature is useful when you want to mock the entire module all at once instead of mocking each provider individually.

CLI Plugins and TypeScript >= 4.8

NestJS CLI plugins will now require TypeScript >= v4.8. This is due to breaking changes in TypeScript v4.8.

Dropping Support for Node.js v12

Since Node.js v12 went end of life (EOL), to use the new features of NestJS v10, a minimum version of Node.js v16 or higher is required.

This also allows the NestJS package to be compiled as ES2021 by default which results in a smaller library size and better performance.

Migration Guidelines

To migrate your existing NestJS project to the latest version, follow the links available below:

Migration from v9 to v10

Migration from v8 to v9

Migration from v7 to v8

Conclusion

NestJS v10 brings a lot of new exciting and improved features as compared to its older versions. If you are using NestJS in your projects please share it via comments.

I hope you have learned something new as I did. If so, kindly like it or share it with others so they can also see it.

References

Below are some of the references which you can follow for more in-depth knowledge

Redis Microservices

SWC or Speedy Web Compiler

Top comments (0)