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, end the request, or pass control to the next middleware.
Click to reveal answer
beginner
Why does the order of middleware matter in Express?
Middleware runs in the order it is added. If the order is wrong, some middleware might not run or might run too late, causing bugs or unexpected behavior.
Click to reveal answer
intermediate
What happens if a middleware does not call next()?
If a middleware does not call next(), the request stops there and no further middleware or route handlers run. This can cause the request to hang.
Click to reveal answer
intermediate
How can middleware ordering affect authentication?
Authentication middleware should run before routes that need protection. If it runs after, unauthorized users might access protected routes.
Click to reveal answer
beginner
Give an example of middleware ordering in Express.
Example: app.use(logger); app.use(auth); app.get('/profile', profileHandler); Logger runs first, then auth, then the route handler.
Click to reveal answer
In Express, what happens if middleware is placed after the route handler?
✗ Incorrect
Middleware runs in the order it is added. If placed after a route handler, it won't run for that route.
What must middleware do to pass control to the next middleware?
✗ Incorrect
Middleware must call next() to pass control to the next middleware or route handler.
Why should authentication middleware run early in the middleware chain?
✗ Incorrect
Running authentication early ensures only authorized users access protected routes.
What is a common use of middleware in Express?
✗ Incorrect
Middleware often logs requests to track server activity.
If middleware does not call next() or end the response, what happens?
✗ Incorrect
Without calling next() or ending response, the request stays open and hangs.
Explain why middleware order is important in Express and give an example.
Think about how requests flow through middleware functions.
You got /4 concepts.
Describe what happens if a middleware forgets to call next() and why this matters.
Consider the flow of control in Express middleware.
You got /4 concepts.