Recall & Review
beginner
What is middleware in NestJS?
Middleware in NestJS is a function that runs before the route handler. It can modify the request or response, or end the request-response cycle.
Click to reveal answer
beginner
How do you apply middleware to a specific route in NestJS?
You apply middleware by implementing the
configure() method in a module and using consumer.apply(MiddlewareClass).forRoutes('route').Click to reveal answer
beginner
What is the purpose of the
next() function in NestJS middleware?The
next() function passes control to the next middleware or route handler. Without calling next(), the request will not continue.Click to reveal answer
intermediate
Can middleware be applied globally in NestJS? How?
Yes, middleware can be applied globally by using
app.use() in the main bootstrap file before starting the app.Click to reveal answer
intermediate
What types of routes can middleware be applied to in NestJS?
Middleware can be applied to string paths, controller classes, or route objects specifying method and path.
Click to reveal answer
In NestJS, where do you define middleware for specific routes?
✗ Incorrect
Middleware for specific routes is defined in the module's configure() method using consumer.apply().
What happens if you forget to call next() in a NestJS middleware?
✗ Incorrect
Without calling next(), the request does not continue to the next middleware or route handler, causing it to hang.
Which method applies middleware globally in NestJS?
✗ Incorrect
app.use() applies middleware globally before any route handlers.
Middleware in NestJS can be applied to which of the following?
✗ Incorrect
Middleware can be applied flexibly to string paths, controller classes, or route objects specifying method and path.
What is the main role of middleware in NestJS?
✗ Incorrect
Middleware processes requests before they reach route handlers, often for logging, authentication, or modifying requests.
Explain how to apply middleware to a specific route in NestJS and why you might want to do this.
Think about controlling which routes get extra processing.
You got /4 concepts.
Describe the difference between applying middleware globally and applying it to specific routes in NestJS.
Consider the scope of middleware application.
You got /4 concepts.