Release - NestJS 11! πŸ¦πŸŽ‰πŸš€

NestJS 11, released in January 2025, introduces several notable enhancements and features aimed at improving developer experience and application performance. Here are the key updates:

1. Logger Enhancements

The default ConsoleLogger has been significantly upgraded to include:

  • Improved formatting for deeply nested objects and arrays.

  • Support for Map and Set structures.

  • Customizable log prefixes.

  • Built-in JSON log support, which can be enabled as follows:

    const app = await NestFactory.create(AppModule, {
      logger: new ConsoleLogger({ json: true }),
    });
    

This JSON logging is particularly beneficial for containerized environments.

2. Enhanced Microservice Flexibility

Significant improvements have been made to microservice transporters like NATS, Kafka, and Redis, offering developers greater flexibility and control. A new unwrap() method allows direct access to underlying client instances for custom operations:

import { NatsConnection } from 'nats';

const serviceRef = app.connectMicroservice({
  transport: Transport.NATS,
  options: { /* NATS connection options */ },
});

const connection = serviceRef.unwrap<NatsConnection>();
console.log(connection.info);

Additionally, the new on() method enables listening to internal client events, and the status observable stream provides real-time updates on client status.

3. Faster Application Startup

The module opaque token generation process has been redesigned to enhance application startup times. Instead of hashing module metadata, the framework now uses object references to determine module equivalence, reducing complexity and performance overhead.

4. Support for Express v5 and Fastify v5

NestJS 11 now supports the latest versions of Express and Fastify. Notably, Express v5 introduces changes to the path routing matching algorithm, which may require adjustments in existing applications. For example, wildcard routes should now use named parameters:

@Get('users/*splat')
findAll() {
  return 'This route will work in Express v5';
}

This update ensures compatibility with the latest features and improvements in these underlying frameworks.

5. Additional Updates

  • Lifecycle Hooks: The order of termination lifecycle hooks (OnModuleDestroy, OnApplicationShutdown, etc.) has been reversed to ensure proper resource cleanup.
  • CacheModule: Updated to use cache-manager v6, now utilizing Keyv as a unified key-value storage interface.
  • New ParseDatePipe: Introduced in @nestjs/common to facilitate easier date handling.
  • Microservice Options: Can now be provided from the Dependency Injection container.
  • IntrinsicException: Allows throwing exceptions that won’t be automatically logged by the framework.
  • @nestjs/cqrs: Now supports request-scoped providers and strongly-typed commands, events, and queries.
  • Reflector Class Improvements: Methods like getAll and getAllAndMerge now correctly infer transformed metadata types.
  • ConfigService Enhancements: The get method now reads configuration values in a different order, allowing custom configuration factories to override process.env values. A new skipProcessEnv option simplifies configuration encapsulation, especially useful in testing scenarios.
1 Like