Routing for Expresss
Express routing maps an HTTP method and URL path to a handler function, such as app.get with a path and a callback. Middleware are functions that run before the handler with access to the request, the response and next, and they are how Express adds behaviour like parsing JSON or serving static files.
Stage: Basics · Part of the Express roadmap · Last reviewed 19 November 2026
What to learn in Routing
- Define routes for GET, POST, PUT and DELETE with route parameters like /users/:id
- Group related routes in an express.Router and mount it under a path prefix
- Write a middleware function that calls next to pass control onward
- Explain why middleware order matters in an Express application
- Serve static files with express.static and parse JSON bodies with express.json
Routing interview questions
What does the next function do in Express middleware?
Calling next passes control to the next middleware or route handler in the stack. If a middleware neither calls next nor sends a response, the request hangs. Calling next with an argument skips to the error-handling middleware.
Why does middleware order matter?
Express runs middleware in the order it is registered. For example, express.json must come before routes that read req.body, and an authentication middleware must come before the routes it protects. Error handlers are registered last.
Where Routing fits in the Express roadmap
Routing belongs to the Basics stage (beginner level). Routing and middleware.
Back to the full Express roadmap