Recall & Review
beginner
What is global middleware in NestJS?
Global middleware in NestJS is a function that runs before every route handler in the application. It can modify requests, responses, or perform actions like logging for all incoming requests.
Click to reveal answer
beginner
How do you apply middleware globally in a NestJS application?
You apply middleware globally by using the
app.use() method inside the main.ts file, before the app starts listening. For example: <br>app.use(yourMiddlewareFunction);Click to reveal answer
intermediate
What is the difference between global middleware and route-specific middleware in NestJS?
Global middleware runs for every request to any route, while route-specific middleware runs only for the routes where it is applied. Global middleware is set in <code>main.ts</code>, route middleware is set in modules using <code>configure()</code> method of the module class implementing <code>NestModule</code>.Click to reveal answer
beginner
Can global middleware in NestJS modify the request and response objects?
Yes, global middleware can modify both the request and response objects. This allows you to add properties, headers, or perform checks before the request reaches the route handler.
Click to reveal answer
beginner
Where in a NestJS project do you typically register global middleware?
Global middleware is typically registered in the
main.ts file, right after creating the app instance and before calling app.listen().Click to reveal answer
Where do you register global middleware in a NestJS app?
✗ Incorrect
Global middleware is registered in main.ts using app.use() before the app starts listening.
What does global middleware affect in a NestJS app?
✗ Incorrect
Global middleware runs for every incoming request to any route.
Which of these is a valid way to apply global middleware in NestJS?
✗ Incorrect
app.use() in main.ts is the correct way to apply global middleware.
Can global middleware modify the request object in NestJS?
✗ Incorrect
Global middleware can modify the request object before it reaches route handlers.
What is the main purpose of global middleware?
✗ Incorrect
Global middleware runs code before every route handler to perform tasks like logging or authentication.
Explain how to set up global middleware in a NestJS application and what it can be used for.
Think about where the app starts and how middleware fits in the request flow.
You got /4 concepts.
Describe the difference between global middleware and route-specific middleware in NestJS.
Consider the scope of middleware application.
You got /4 concepts.