What happens during an Express request?
Practice this questionWANT TO UNDERSTAND THE CONCEPT FIRST?Learn The Express request lifecycle
Definition:
Express handles requests through a sequence of registered middleware and route handlers. Middleware can inspect or change the request, stop it with a response, or pass it onward. The order of registration matters because later handlers see the result of earlier ones.
Key points:
-
Matching middleware runs in registration order.
-
A route handler calls the service and sends a response.
-
Middleware must send a response or call
next(); otherwise the request can hang. -
A router groups related routes; controllers translate HTTP details while services implement business rules.
Request flow:
- Client sends a request; Express matches the registered path and middleware.
- Parsing middleware reads permitted input and authentication identifies the caller.
- Authorization and validation reject requests that should not continue.
- The controller calls business logic in a service.
- The service completes database or external work.
- A response is sent, or an error is forwarded to error middleware.
Interview point:
- Explain the full path from request parsing and authentication to validation, business logic and one final response.
Adapted from 02_NODE_EXPRESS_HTTP.md · “What happens during an Express request?”. Code examples are study fragments. Difficulty and core labels are editorial estimates; version-specific behavior should be checked against your project.