Recall & Review
beginner
What is middleware in Express?
Middleware is a function that runs during the request-response cycle. It can modify the request or response, or end the request.
Click to reveal answer
beginner
How can you run middleware only for certain routes in Express?
You can attach middleware only to specific routes by passing it as an argument before the route handler, so it runs conditionally.
Click to reveal answer
intermediate
How do you conditionally execute middleware based on a request property?
Inside the middleware, check the request property (like req.path or req.method). Call next() only if the condition is met; otherwise, skip or respond.
Click to reveal answer
beginner
What does calling next() do in Express middleware?
Calling next() passes control to the next middleware or route handler in the stack.
Click to reveal answer
intermediate
Give an example of conditional middleware execution in Express.
Example: Use middleware only if req.query.admin is 'true'. Inside middleware, check if req.query.admin === 'true', then call next(); else respond with 403.
Click to reveal answer
What is the purpose of middleware in Express?
✗ Incorrect
Middleware functions run during the request-response cycle to process requests or responses.
How do you run middleware only for a specific route in Express?
✗ Incorrect
Passing middleware before the route handler runs it only for that route.
What happens if you don't call next() inside middleware?
✗ Incorrect
Without calling next(), Express does not continue to the next middleware or route.
Which property can you check to conditionally run middleware?
✗ Incorrect
req.method holds the HTTP method and can be used to conditionally run middleware.
How can you skip middleware execution for some requests?
✗ Incorrect
Inside middleware, you can decide to call next() or respond early based on conditions.
Explain how to run middleware conditionally in Express based on the request path.
Think about how to decide inside middleware whether to continue or stop.
You got /4 concepts.
Describe the role of next() in Express middleware and what happens if it is not called.
Consider the flow of request handling in Express.
You got /3 concepts.