Express req.route Property
What you’ll learn
- What route metadata
req.routecontains. - Where in the request lifecycle
req.routeis available. - How to inspect route path/method for diagnostics.
- Why this property is mainly for debugging, not core logic.
Usage syntax
javascript
req.route
req.route.path
req.route.methods1
Inspect matched route path in handler
javascript
app.get('/users/:id', function (req, res) {
res.json({
routePath: req.route.path,
methods: req.route.methods
});
});2
Route-level debug logging
javascript
app.post('/orders', function (req, res) {
console.log('Matched route:', req.route.path, 'Method:', req.method);
res.send('Order created');
});❓ FAQ
It is an object representing the route currently matched for the request.
Commonly route path and method map metadata, useful for diagnostics/logging.
It is typically available inside matched route handlers, not in unrelated middleware before route resolution.
Usually no. It is best for observability and debugging rather than core business logic.
req.path is request URL path, while req.route is matched route definition metadata.
Did you know?
req.route describes the currently matched route definition and is useful for debugging route behavior.
4 people found this page helpful
