Express.js req.route Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

req.route is the currently matched Route object. Once Express picks a route for the request, this property describes that definition — the pattern you registered, which HTTP methods it handles, and its handler stack.

Use it for logging and debugging (“which route ran?”). For URL data, prefer req.path and req.params. It is set when a route dispatches — not in early global middleware before a match.

Syntax

Read req.route in your Express.js route handler. Start with this line.

Express
req.route              // Route object (or undefined)
req.route.path         // registered pattern, e.g. '/user/:id'
req.route.methods      // { get: true, … }
req.route.stack        // handler layers for this route
CallWhat it does
req.route // Route object (or undefined)Primary signature.
req.route.path // registered pattern, e.g. '/user/:id'Related call form.
req.route.methods // { get: true, … }Related call form.
req.route.stack // handler layers for this routeRelated call form.

Install with npm install express. Create the app with const app = express() before you use this API in an Express.js tutorial project.

Library declarations
Express
const express = require("express");
const app = express();

req.route              // Route object (or undefined)
req.route.path         // registered pattern, e.g. '/user/:id'
req.route.methods      // { get: true, … }
req.route.stack        // handler layers for this route

Parameters

This Express.js property is read from the request or response — it has no call parameters.

Return Value

req.route is the currently matched Route object (path template, methods, …) once routing has selected a route. It may be undefined in early middleware.

Express
app.get('/users/:id', (req, res) => {
  req.route.path;    // '/users/:id'
  req.route.methods; // { get: true, ... }
});

Express.js Examples

Example 1 — Inspect the Matched Route

Return the registered pattern and methods for a parameterized GET route.

Express
const express = require('express');
const app = express();

app.get('/user/:id', (req, res) => {
  res.json({
    routePath: req.route.path,
    methods: req.route.methods,
    paramId: req.params.id
  });
});

app.listen(3000);

How It Works

  1. Register the pattern. app.get('/user/:id', …) creates a Route with that path.
  2. Match fills req.route. When /user/42 arrives, Express sets req.route to that route object.
  3. Read metadata. req.route.path stays /user/:id; methods shows { get: true }.
  4. Params separately. The concrete value 42 lives on req.params.id, not on req.route.path.

Example 2 — Log Which Route Handled the Request

Useful debug line inside a handler — pattern plus real method.

Express
const express = require('express');
const app = express();

app.post('/orders', (req, res) => {
  console.log(
    'Matched:', req.route.path,
    '| method:', req.method,
    '| methods map:', req.route.methods
  );
  res.status(201).send('Order created');
});

app.listen(3000);

How It Works

  1. Handler runs after match. So req.route is defined here.
  2. Pattern from the route. req.route.path is /orders.
  3. Request method. req.method is the live verb (POST); req.route.methods lists what the route supports.
  4. Observability only. Great for logs — keep order-creation logic separate.

Example 3 — Pattern vs Actual Path

Side-by-side: registered pattern, request path, and params.

Express
const express = require('express');
const app = express();

// Early middleware — route has not matched yet
app.use((req, res, next) => {
  console.log('Before match, req.route =', req.route); // undefined
  next();
});

// Express 5 optional style often looks like: /user/{:id}
app.get('/user/:id', (req, res) => {
  res.json({
    routePath: req.route.path, // '/user/:id'
    path: req.path,            // '/user/42'
    params: req.params         // { id: '42' }
  });
});

app.listen(3000);

How It Works

  1. Early middleware first. The top app.use runs before any route — req.route is still undefined.
  2. Then the route matches. The GET /user/:id handler runs with req.route set.
  3. Three different views. Pattern (req.route.path), URL path (req.path), captured values (req.params).
  4. Express 5 note. Optional segments are often written /{:id}; classic /:id still works for required params.

Runtime Support

req.route is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not have this API.

✓ Server · Express 4 & 5

req.route

Works wherever Express runs: Node.js is the primary target. Bun and Deno can run many Express apps with compatibility layers. Not available in the browser.

Server Node.js runtime API
Node.js 18+ for Express 5 · 14+ typical for Express 4
Supported
Bun Express-compatible server apps
Supported
Deno Via npm compatibility / adapters
Supported
req.route Express on Node.js

Bottom line: Study and run these examples with Node.js and the express package. Copy a snippet into a local file and start the server with node.

Frequently Asked Questions

It is the currently matched Route object for the request. It exposes the route pattern (path), registered methods, and the handler stack.
Inside a matched route handler (and route-level middleware on that route). Early app.use middleware that runs before a route matches usually does not have it yet.
req.route.path is the route pattern you registered (for example /user/:id). req.path is the actual URL path of this request (for example /user/42).
Usually no. Prefer it for logging, debugging, and metrics. Keep core logic on params, body, and explicit checks.
No. It is a server-side Express property. Browsers only send HTTP requests to your app.

Next: req.secure

Detect HTTPS with the boolean req.secure property.

req.secure tutorial →

CODETOFUN NEWS

Stay Ahead in Tech

Get the latest IT news, programming updates, and technology trends directly on your phone.

Your daily dose of tech, straight to your feed.

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful