Recall & Review
beginner
What is middleware in Express?
Middleware is a function that has access to the request (req), response (res), and next middleware function in the app's request-response cycle. It can modify req and res or end the request-response cycle.
Click to reveal answer
beginner
What does the 'next' function do in Express middleware?
The 'next' function passes control to the next middleware function in the stack. Without calling next(), the request will hang and not proceed.
Click to reveal answer
beginner
In what order are middleware functions executed?
Middleware functions are executed in the order they are added to the Express app or router. Each calls next() to pass control to the next middleware.
Click to reveal answer
intermediate
What happens if a middleware does not call next() or end the response?
The request will hang because Express waits for the middleware to either call next() or send a response. This causes the client to wait indefinitely.
Click to reveal answer
intermediate
How can middleware modify the request and response objects?
Middleware can add, change, or remove properties on req and res objects. For example, adding user info to req or setting headers on res before sending.
Click to reveal answer
What are the three parameters of an Express middleware function?
✗ Incorrect
Express middleware functions always receive req, res, and next as parameters.
What happens if you forget to call next() in a middleware?
✗ Incorrect
Without calling next() or ending the response, the request will hang waiting.
Which middleware runs first in Express?
✗ Incorrect
Middleware executes in the order it is added to the app or router.
How can middleware modify the response before sending it?
✗ Incorrect
Middleware can set headers or data on res before sending the response.
What is the purpose of calling next() in middleware?
✗ Incorrect
Calling next() passes control to the next middleware function.
Explain how middleware functions work together in Express using req, res, and next.
Think about how a relay race passes the baton from one runner to the next.
You got /4 concepts.
Describe what happens if a middleware neither calls next() nor sends a response.
Imagine stopping in the middle of a line without telling anyone.
You got /4 concepts.