What is Request/Response middleware in Web Frameworks?

Updated Apr 28, 2026

Short answer

Code that sits between the server and the application logic to inspect or modify incoming requests and outgoing responses.

Deep explanation

Layering allows for 'separation of concerns.' Each layer has a specific responsibility and communicates only with the layer directly below it. Middleware, like Express.js middleware, intercepts the flow of execution to perform tasks like authentication before the main logic runs.

Real-world example

Logging every visitor's IP address in a web application using a simple middleware function.

Common mistakes

  • Creating circular dependencies between layers.

Follow-up questions

  • What happens if next() is not called in middleware?

More Layering & Middleware interview questions

View all →