Complete the code to import the MiddlewareConsumer from NestJS.
import { [1] } from '@nestjs/common';
The MiddlewareConsumer is imported from @nestjs/common to configure middleware in NestJS.
Complete the code to implement the NestJS middleware interface.
export class LoggerMiddleware implements [1] {
Middleware classes in NestJS implement the NestMiddleware interface.
Fix the error in the middleware method signature.
use(req: Request, res: Response, [1]) {The use method in NestJS middleware receives next as a NextFunction type from Express.
Fill both blanks to apply middleware to all routes in a module.
configure(consumer: [1]) { consumer .apply(LoggerMiddleware) .[2]('*'); }
The configure method receives a MiddlewareConsumer to apply middleware. The forRoutes method applies it to all routes.
Fill all three blanks to create a middleware that logs the request method and URL, then calls next.
export class LoggerMiddleware implements NestMiddleware { use(req: [1], res: [2], [3]) { console.log(`${req.method} ${req.url}`); next(); } }
The middleware use method parameters are Request, Response, and next of type NextFunction. This allows logging and passing control to the next middleware.