Announcing NestJS 8: What’s New?

Kamil Mysliwiec | Trilon Consulting
Kamil Mysliwiec
Note: This is a previous Nest release announcement
🌟 Read about the latest release - NestJS version 9 here

Today I am thrilled to announce the official release of NestJS 8. This is a major release spanning the entire platform, including the framework, numerous improvements to the @nestjs/graphql and @nestjs/config packages, CLI, and updated documentation.

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 Trison Thomas

Let's dive right in!

What’s in this release?

This release brings lots of great features and long-awaited improvements. There are far too many to list here, but let’s take a high-level look at some of the most exciting ones.

API versioning

Traditionally in Node.js (and NestJS) applications, API versioning has never had a "right way" of being done, as there are many ways of achieving it.

In v8, you'll be able to have different versions of your controllers or individual routes running within the same application. We'll support 3 different types of versioning as well: URI versioning, Header versioning, and Media Type versioning.

URI Versioning The version will be passed within the URI of the request (default)
Header Versioning A custom request header will specify the version
Media Type Versioning The Accept header of the request will specify the version

A version can be applied to a controller, setting the version for all routes within the controller:

@Controller({
path: 'cats',
version: '1', // 👈
})
export class CatsController {
@Get()
findAll(): string {
return 'This action returns all cats for version 1';
}
}

or alternatively, you can apply it to an individual route:

@Version('1') // 👈
@Get()
findAll(): string {
return 'This action returns all cats for version 1';
}

NOTE: Special thanks to @rich-w-lee and his amazing contribution (#6278) to this feature!

Learn more about the versioning feature here.

NestJS + Serverless documentation

Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on-demand, taking care of the servers on behalf of their customers.

Properly running Nest applications in a serverless environment can sometimes be tricky. To make things simpler, we added a dedicated chapter in the official documentation that includes benchmarks, both runtime and build time optimizations, several basic examples and integrations, as well as describing what some of the main pain points are when it comes to NestJS serverless applications & how you can go about trying to tackle them.

Lazy-loading modules

By default, modules are eagerly loaded, which means that as soon as the application loads, as do all of the modules, whether or not they are immediately necessary. While this is fine for most applications, it may become a bottleneck for apps/workers running in the serverless environment, where the startup latency (or "cold start") is crucial.

Lazy loading can help decrease bootstrap time by loading only modules required by the specific serverless function invocation. In addition, you could also load other modules asynchronously once the serverless function is "warm" to speed-up the bootstrap time for subsequent calls even further (known as: deferred modules registration).

HINT: If you're familiar with the Angular framework, you might have seen this term "lazy-loading modules" before. Be aware that this technique is functionally different in Nest than it is in Angular - so although these two may share similar naming conventions - make sure to think about this as an entirely different feature.

In v8, we added a way to load modules on-demand (lazily). You can learn more here.

WARNING: Controllers, resolvers, and gateways registered inside lazy-loaded modules will not behave as expected. Similarly, you cannot register middleware functions (by implementing the MiddlewareConsumer interface) on-demand.

Template literal types and ConfigService

With the template literal types now available in TypeScript v4.2, we are able to implement a new infer feature that lets us infer the type of a nested custom configuration object's property, even when using dot notation, as shown here:

constructor(private configService: ConfigService<{ database: { host: string } }>) {
const dbHost = this.configService.get('database.host', { infer: true });
// typeof dbHost === "string"
}

Previously, this would have been typed as any.

Support multiple event subscribers

In v8, you will be able to register multiple event subscribers (using the @EventPattern decorator) within a single microservice, and they all will be executed asynchronously in reaction to the incoming event.

This was one of the oldest, long-awaited requests from the community, and it's finally being shipped in this major release!

Logger refactor/improvements

Previously (before v8), when a custom logger instance was used (registered within the framework's IoC container), you'd either miss the first initialization messages/errors (since the instance has not been yet created), or they would be logged with the default, built-in logger (which made output logs inconsistent).

To address this problem, we introduced a new logs buffering feature:

const app = await NestFactory.create(ApplicationModule, {
bufferLogs: true, // 👈
});
app.useLogger(new MyLogger());

In the example above, we set the bufferLogs to true to make sure all logs will be buffered until a custom logger is attached (MyLogger in this case) and the application initialization process either completes or fails.

If the initialization process fails, Nest will fallback to the original ConsoleLogger to print out any reported error messages.

Note that you can also set the autoFlushLogs to false (the default is true) to manually flush logs (using the Logger#flush() method).

If the initialization process succeeds, then all buffered logs will be printed using the logger instance you provided.

Upgraded dependencies

Nest v8 finally brings support for Socket.io 4.0 and NATS v2 that weren't compatible with v7. Also, Nest v8 will use the latest version of RxJS (v7).

Enjoy v8!

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!


Official NestJS Courses 📚

Looking to level-up your NestJS and Node.js ecosystem skills?

🚀 The NestJS Fundamentals Course is now LIVE and 25% off for a limited time!

In this extensive workshop-style course, we'll incrementally build a NestJS application together.

We'll learn about all of the fundamental building blocks, interact with both SQL & NoSql databases, use modern Node.js application techniques, unit / e2e testing, tips, tricks, and overall best-practices!


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!

<script>

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.

T-Shirts and hoodies

If you enjoy using NestJS and you would like to donate to our Open Source work (have your cake 🍰 and eat it), we just launched the official NestJS store 👕 where you can buy hoodies, T-shirts, and accessories!


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
#NodeJS

Share this Post!

📬 Trilon Newsletter

Stay up to date with all the latest Articles & News!

More from the Trilon Blog .

Jay McDoniel | Trilon Consulting
Jay McDoniel

NestJS Metadata Deep Dive

In this article we'll be doing a deep-dive and learning about how NestJS uses Metadata internally for everything from dependency injection, to decorators we use everyday!

Read More
Kamil Mysliwiec | Trilon Consulting
Kamil Mysliwiec

NestJS v10 is now available

Today I am excited to announce the official release of Nest 10: A progressive Node.js framework for building efficient and enterprise-grade, server-side applications.

Read More
Manuel Carballido | Trilon Consulting
Manuel Carballido

Implementing data source agnostic services with NestJS

Learn how to implement data source logic in an agnostic way in yours NestJS applications.

Read More

What we do at Trilon .

At Trilon, our goal is to help elevate teams - giving them the push they need to truly succeed in today's ever-changing tech world.

Trilon - Consulting

Consulting .

Let us help take your Application to the next level - planning the next big steps, reviewing architecture, and brainstorming with the team to ensure you achieve your most ambitious goals!

Trilon - Development and Team Augmentation

Development .

Trilon can become part of your development process, making sure that you're building enterprise-grade, scalable applications with best-practices in mind, all while getting things done better and faster!

Trilon - Workshops on NestJS, Node, and other modern JavaScript topics

Workshops .

Have a Trilon team member come to YOU! Get your team up to speed with guided workshops on a huge variety of topics. Modern NodeJS (or NestJS) development, JavaScript frameworks, Reactive Programming, or anything in between! We've got you covered.

Trilon - Open-source contributors

Open-source .

We love open-source because we love giving back to the community! We help maintain & contribute to some of the largest open-source projects, and hope to always share our knowledge with the world!

Explore more

Write us a message .

Let's talk about how Trilon can help your next project get to the next level.

Rather send us an email? Write to:

hello@trilon.io
© 2019-2023 Trilon.