Recall & Review
beginner
What is functional middleware in NestJS?
Functional middleware in NestJS is a simple function that takes a request, response, and next callback to process HTTP requests before they reach route handlers.
Click to reveal answer
beginner
How do you define a functional middleware in NestJS?
You define it as a function with parameters (req, res, next) where you can modify the request or response, then call next() to pass control to the next middleware or route handler.
Click to reveal answer
intermediate
How do you apply functional middleware to routes in NestJS?
You apply functional middleware inside the configure() method of a module by using the MiddlewareConsumer's apply() method and specifying the routes with forRoutes().
Click to reveal answer
beginner
What is the role of the next() function in functional middleware?
The next() function passes control to the next middleware or route handler. Without calling next(), the request will not continue and may hang.
Click to reveal answer
intermediate
Can functional middleware in NestJS be asynchronous? How?
Yes, functional middleware can be asynchronous by returning a Promise or using async/await syntax. You must still call next() after async operations complete.
Click to reveal answer
What parameters does a functional middleware function in NestJS receive?
✗ Incorrect
Functional middleware receives the parameters req (request), res (response), and next (callback to continue).
Where do you apply functional middleware in a NestJS application?
✗ Incorrect
Functional middleware is applied inside the configure() method of a module using MiddlewareConsumer.
What happens if you forget to call next() in functional middleware?
✗ Incorrect
Without calling next(), the request does not move forward and will hang.
Can functional middleware modify the request object?
✗ Incorrect
Functional middleware can modify the request object to add data or change values.
How do you specify which routes a functional middleware applies to?
✗ Incorrect
You specify routes using forRoutes() when applying middleware in the configure() method.
Explain how to create and apply a functional middleware in NestJS.
Think about the middleware function signature and where it is registered.
You got /5 concepts.
Describe the importance of calling next() in functional middleware and what happens if you don't.
Consider the flow of request processing.
You got /4 concepts.