Today I am thrilled to announce the official release of NestJS 10. This release brings lots of bug fixes, improvements, and new features. There are far too many to list here, but let’s take a high-level look at some of the most exciting ones!
In case you're not familiar with NestJS, it is a TypeScript Node.js framework that helps you build enterprise-grade efficient and scalable Node.js applications.
Photo by Piotr Musioł
Let's dive right in!
NestJS ❤️ SWC
SWC (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.
In v10, you can use SWC by simply passing the -b swc
flag to the nest start
command, as follows:
$ nest start -b swc
Or by setting the compilerOptions.builder
property in your nest-cli.json
file, as follows:
{ "compilerOptions": { "builder": "swc" }}
SWC does not perform any type checking itself (as opposed to the default TypeScript compiler), so to turn it on, you need to use the --type-check
flag:
$ nest start -b swc --type-check
HINT Type-checking must be enabled when using CLI Plugins ⚠️!
This command will instruct the Nest CLI to run tsc
in noEmit
mode alongside SWC, which will asynchronously perform type checking. Again, instead of passing the --type-check
flag you can also just set the compilerOptions.typeCheck
property to true
in your nest-cli.json
file, like so:
{ "compilerOptions": { "builder": "swc", "typeCheck": true }}
You can also use jest
and vitest
in combination with SWC. To learn more, check out the SWC integration recipe in the NestJS documentation.
Vitest is a fast and lightweight test runner designed to work with Vite. It provides a modern, fast, and easy-to-use testing solution that can be integrated with NestJS projects.
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();
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.
Overriding test modules will help make things much simpler when you need to mock a module that has a lot of providers. Learn more about the new overriding test module feature here.
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 }, });
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 tohello
,hallo
andhxllo
h*llo
subscribes tohllo
andheeeello
h[ae]llo
subscribes tohello
andhallo
, but nothillo
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. You can learn more about the @nestjs/cache-manager
package here.
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.
Migration from Nest v9
In order to migrate your existing project, follow the guidelines that are available here. Also, make sure to get rid of all deprecation messages that may appear in your console.
Enjoy v10!
We're excited to see how you use the latest version of NestJS.
Make sure to follow Nest on Twitter @nestframework to stay up to date with all the latest announcements!
Enterprise Consulting & Support
Our official NestJS Enterprise Consulting includes a broad range of services to empower your team.
We work alongside you to meet your deadlines while avoiding costly tech debt. Challenging issue? We've got you covered.
- Providing technical guidance & architectural reviews
- Mentoring team members
- Addressing security & performance concerns
- Performing in-depth code reviews
- Long-term support (LTS) & upgrade assistance
Our goal is to help you get to market faster. Nest core team members will help you utilize best practices and choose the right strategy for unique goals. You can learn more on the enterprise.nestjs.com.
Support the NestJS Project
Nest is an MIT-licensed open source project with its ongoing development made possible thanks to the support by the community and our sponsors. Thank you!
This framework is a result of the long days, sleepless nights, and busy weekends. And we fully rely on the goodness ❤️ of the people. If you want to join them, you can read more here.
Thank you
To all backers, sponsors, contributors, and community, thank you once again! This product is for you. And this is only the beginning of the long 🚀 story.
Become a Backer or Sponsor to Nest by donating to our open collective. ❤
Learn NestJS - Official NestJS Courses 📚
Level-up your NestJS and Node.js ecosystem skills in these incremental workshop-style courses, from the NestJS Creator himself, and help support the NestJS framework! 🐈🚀 The NestJS Fundamentals Course is now LIVE and 25% off for a limited time!
🎉 NEW - NestJS Course Extensions now live!
- NestJS Advanced Concepts Course now LIVE!
- NestJS Authentication / Authorization Course now LIVE!
- NestJS GraphQL Course (code-first & schema-first approaches) are now LIVE!
- NestJS Authentication / Authorization Course now LIVE!