NestMiddleware is the interface that class-based middleware in NestJS implements. It defines the use(req, res, next) method, matching the Express middleware signature. Classes must also be decorated with @Injectable() and fully support dependency injection.

@Injectable()
export class LoggerMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    console.log('Request...');
    next();
  }
}

Middleware runs before route handlers and can modify request/response objects, end the cycle, or pass control via next(). It is configured via the module’s configure() method, not in @Module().