Recall & Review
beginner
What is middleware in Node.js Express?
Middleware is a function that runs during the request-response cycle. It can modify the request or response, or end the cycle by sending a response.
Click to reveal answer
beginner
Why does the order of middleware matter in Express?
Middleware runs in the order it is added. If a middleware ends the response early, later middleware won't run. So, order controls how requests are handled step-by-step.
Click to reveal answer
intermediate
What happens if you place error-handling middleware before regular middleware?
Error-handling middleware should come after regular middleware. If placed before, it won't catch errors from later middleware because it runs too early.
Click to reveal answer
intermediate
How can middleware ordering affect authentication?
Authentication middleware should run before routes that need protection. If placed after, unauthorized users might access protected routes.
Click to reveal answer
beginner
What is the effect of calling next() in middleware?
Calling next() passes control to the next middleware in the stack. If next() is not called, the request stops there and later middleware won't run.
Click to reveal answer
In Express, what happens if a middleware does NOT call next() or send a response?
✗ Incorrect
If middleware neither calls next() nor sends a response, the request stays open and the client waits forever.
Where should authentication middleware be placed in Express?
✗ Incorrect
Authentication middleware must run before protected routes to check user access before handling the request.
What is the correct order for error-handling middleware in Express?
✗ Incorrect
Error-handling middleware should be last to catch errors from all previous middleware and routes.
If you want to log every request, where should the logging middleware be placed?
✗ Incorrect
Logging middleware should be first to capture all incoming requests before any other processing.
What does calling next('route') do in Express middleware?
✗ Incorrect
Calling next('route') skips remaining middleware for the current route and moves to the next matching route.
Explain why middleware order matters in Express and give an example where wrong order causes a problem.
Think about how requests flow through middleware functions.
You got /4 concepts.
Describe how you would organize middleware for logging, authentication, routes, and error handling in an Express app.
Consider the order that makes the app secure and easy to debug.
You got /4 concepts.