NestJS v10 is here! What’s new?

kristiyan_velkov

Kristiyan Velkov

Posted on June 20, 2023

NestJS v10 is here! What’s new?

SWC

1SWC (Speedy Web Compiler) is an extensible Rust-based platform that can be used for both compilation and bundling. Using SWC with Nest CLI is a great and simple way to significantly speed up your development process.

SWC is approximately x20 times faster than the default TypeScript compiler.

Image description

You can also use jest and vitest in combination with SWC. To learn more, check out the SWC integration recipe in the NestJS documentation.


Overriding modules in tests

NestJS 10 introduces a new feature that allows you to override modules in tests. This feature is especially useful when you want to mock the entire module all at once instead of mocking each provider individually.

Test.createTestingModule({
  ...
})
  .overrideModule(LoggerModule)
  .useModule(LoggerTestingModule)
  .compile();
Enter fullscreen mode Exit fullscreen mode

As long as you have a LoggerTestingModule that exports the same providers as the LoggerModule (and so provides the same public API), Nest will use the LoggerTestingModule module instead of the LoggerModule in your tests.


Redis wildcard subscriptions

In v10, we added support for Redis wildcard subscriptions. This feature allows you to subscribe to all messages that match a given pattern. As long as you set the wildcards configuration property to true in your microservice configuration, as follows:

const app = await NestFactory.createMicroservice<MicroserviceOptions>(
  AppModule,
  {
    transport: Transport.REDIS,
    options: {
      host: 'localhost',
      port: 6379,
      wildcards: true, // 👈 THIS IS NEW
    },
  }
); 
Enter fullscreen mode Exit fullscreen mode

Redis will use psubscribe/pmessage (learn more about Redis psubscribe) instead of subscribe/message under the hood. With wildcards enabled, you can use glob-style patterns in your subscriptions, as follows:

  • h?llo subscribes to hello, hallo and hxllo
  • h*llo subscribes to hllo and heeeello
  • h[ae]llo subscribes to hello and hallo, but not hillo

Cache module

The CacheModule has been removed from the @nestjs/common package and is now available as a standalone package - @nestjs/cache-manager. This change was made to avoid unnecessary dependencies in the @nestjs/common package.


Dropping support for Node.js v12

As of NestJS 10, we no longer support Node.js v12, as v12 went EOL on April 30, 2022. This means that NestJS 10 requires Node.js v16 or higher. This decision was made to allow us to finally set target to ES2021 in our TypeScript configuration, instead of shipping polyfills as we did in the past.

From now on, every official NestJS package will be compiled to ES2021 by default, which should result in a smaller library size and sometimes even (slightly) better performance.


CLI Plugins TypeScript >= 4.8

NestJS CLI Plugins (available for @nestjs/swagger and @nestjs/graphql packages) will now require TypeScript >= v4.8 and so older versions of TypeScript will no longer be supported. The reason for this change is that in TypeScript v4.8 introduced several breaking changes in its Abstract Syntax Tree (AST) which we use to auto-generate OpenAPI and GraphQL schemas.

Please, read more in the official website => https://trilon.io/blog/nestjs-10-is-now-available


Image description

linkedin


Image description

If you like my work and want to support me to work hard, please donate via:

Revolut website payment or use the QR code above.

Thanks a bunch for supporting me! It means a LOT 😍

💖 💪 🙅 🚩
kristiyan_velkov
Kristiyan Velkov

Posted on June 20, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related