@nestjs/core
- Interceptors feature (docs)
- Guards feature (docs)
@Shared()
deprecated (modules are singletons by default)@SingleScope()
decorator (read more in the docs)- New response handling approach (return plain value / Promise / Observable)
- Async components
- New
INestApplication
methods (for exampleuse()
wrapper)
@nestjs/microservices
- Possibility to return Promise / Observable / plain value
- Guards & Interceptors & Pipes & Exception Filters integration
@nestjs/websockets
- Possibility to return Promise / Observable / plain value
- Guards & Interceptors & Pipes & Exception Filters integration
@nestjs/testing
- Completely rewritten testing package (docs)
@nestjs/core
- Hierarchical injector bugfix,
- Middlewares
@UseFilters()
bugfix (#95).
@nestjs/microservices
- TCP server / client bugfix (#91)
@nestjs/common - BREAKING CHANGE
- You should now pass objects into
@UseFilters()
decorator instead of metatypes, - Exception Filters can't inject dependencies (they're not coupled with modules),
@ExceptionFilters()
is deprecated, use@UseFilters()
instead.INestApplication
has new methods -useGlobalFilters()
anduseGlobalPipes()
,- New lifecycle hook -
OnModuleDestroy
interface.
@nestjs/core
@Pipe()
feature (async & sync),- Exception Filters can have global, controller and method scope.
@nestjs/websockets - BREAKING CHANGE
- Use
useWebSocketAdapter()
instead ofsetIoAdapter()
, - You can port any WS library - just implement
WebSocketAdapter
(@nestjs/common).
@nestjs/microservices - BREAKING CHANGE
- Now methods have to return
Observable
, and they receive only one argumentdata
, - Microservices can return multiple values, but after emitting
Observable
has to be COMPLETED! - You can port any transport strategy instead of built-in Redis/TCP, just implement
CustomTransportStrategy
.
@nestjs/common, @nestjs/websockets
INestApplication
andINestMicroservice
has new method now -setIoAdapter()
,- Ability to use custom
IoAdapter
@nestjs/common, @nestjs/websockets, @nestjs/microservices
INestApplication
andINestMicroservice
has new method now -setIoAdapter()
,- Ability to use custom
IoAdapter
@nestjs/common, @nestjs/core
INestApplication
has new methods now -init()
,setGlobalPrefix()
,connectMicroservice()
,close()
,startAllMicroservices()
,INestMicroservice
has new method -close()
@nestjs/common
Req()
(Request()
) andRes()
(Response()
) aliases to avoid conflicts with express typings
- Hierarchical injector improvements
@Shared(token?: string)
decorator for scoped, shared Modules- Modules are not singletons anymore
- Added
iterare
library for applying multiple transformations to a collection Logger
service is public,- Nest is now splitted into feature packages:
@nestjs/core
@nestjs/common
@nestjs/microservices
@nestjs/testing
@nestjs/websockets
rxjs
,redis
andreflect-metadata
moved intopeerDependencies
@Patch()
support
- Added Gateway Middlewares support:
@WebSocketGateway({
port: 2000,
middlewares: [ChatMiddleware],
})
Gateway Middleware example:
@Middleware()
export class ChatMiddleware implements GatewayMiddleware {
public resolve(): (socket, next) => void {
return (socket, next) => {
console.log('Authorization...');
next();
};
}
}
- New Gateway lifecycle interfaces
OnGatewayInit
,OnGatewayConnection
,OnGatewayDisconnect
@SubscribeMessage()
now accepts also plain strings:
@SubscribeMessage('event')
@Controller()
now accepts also plain strings:
@Controller('users')
HttpStatus
(HttpStatus.OK
etc.) enumerator- Route params decorators support
Request: () => ParameterDecorator
Response: () => ParameterDecorator
Next: () => ParameterDecorator
Query: (property?: string) => ParameterDecorator
Body: (property?: string) => ParameterDecorator
Param: (property?: string) => ParameterDecorator
Session: () => ParameterDecorator
Headers: (property?: string) => ParameterDecorator
MiddlewaresBuilder
->MiddlewaresConsumer
- Exception Filters support
@ExceptionFilters(CustomExceptionFilter, NextExceptionFilter)
export class UsersController {}
Exception filter example:
export class CustomException {}
@Catch(CustomException)
export class CustomExceptionFilter implements ExceptionFilter {
public catch(exception, response) {
response.status(500).json({
message: 'Custom exception message.',
});
}
}
- Module injection support:
export class UsersController {
constructor(private module: UsersModule) {}
}
ModuleRef
support
- MiddlewareBuilder:
use()
deprecated, useapply()
instead - MiddlewareBuilder: new
apply()
method
- Support for
@Post
,@Get
,@Delete
,@Put
,@All
decorators - Added ability to pass data to middleware metatypes
@Inject
->@Dependencies
@Inject
decorator for custom constructor parameters- Custom providers support (useClass, useValue, useFactory)
- Microservices support (TCP & Redis transports)
- NestRunner -> NestFactory
- Simplify application initialization & configuration
- Added abillity to pass custom express instance
@Inject
decorator for ES6+- SocketGateway -> WebSocketGateway
- GatewayServer -> WebSocketServer