Recall & Review
beginner
What is application-level middleware in Express?
Application-level middleware is a function that runs during the request-response cycle for all or specific routes in an Express app. It can modify requests, responses, or end the request.
Click to reveal answer
beginner
How do you add application-level middleware in Express?
Use
app.use() to add middleware that applies to all routes, or add middleware as additional arguments to specific route handlers like app.get('/path', middleware, handler).Click to reveal answer
beginner
What are the three arguments of an Express middleware function?
The middleware function receives
req (request), res (response), and next (a function to pass control to the next middleware).Click to reveal answer
intermediate
What happens if you don’t call
next() in middleware?The request will hang because Express won’t move to the next middleware or route handler. You must call
next() unless you send a response.Click to reveal answer
intermediate
Can application-level middleware modify the request or response objects?
Yes, middleware can add properties or change
req and res objects to share data or customize behavior for later middleware or routes.Click to reveal answer
Which method adds application-level middleware to all routes in Express?
✗ Incorrect
app.use() adds middleware that runs for all routes or specific paths.
What is the purpose of the
next argument in middleware?✗ Incorrect
next() moves the request to the next middleware or route handler.
If middleware does not call
next() or send a response, what happens?✗ Incorrect
Without calling next() or sending a response, the request stays open and hangs.
How can you apply middleware only to a specific route?
✗ Incorrect
You can add middleware as an argument before the route handler to apply it only to that route.
Which of these is NOT a typical use of application-level middleware?
✗ Incorrect
Handling database connections is typically managed outside of middleware, such as at application startup with connection pools.
Explain how application-level middleware works in Express and how you add it to your app.
Think about how middleware fits between request and response.
You got /5 concepts.
Describe what happens if you forget to call next() in your middleware function.
Imagine the request is stuck waiting for something.
You got /4 concepts.