Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

Express.js · Pipe

req.url

req.url is the request URL exposed on Express's request object. It comes from Node's HTTP module and may be rewritten by mounted middleware during internal routing.

How it works

req.url exposes the URL associated with the incoming request, including its path and query portion. Express inherits this property from Node.js's HTTP request object, and middleware such as mounted applications may rewrite it while processing the request.

Syntax

req.url

Returns

String

Key points

  • req.url is accessed from Express's request object inside handlers and middleware.
  • The related req.originalUrl property is the option for retaining the unmodified URL.
  • Express permits internal middleware routing logic to rewrite req.url.
  • A URL value can contain both a route path and a query string.

Common mistakes

  • This is inherited from Node's HTTP request object rather than defined directly by Express.
  • When middleware is mounted under a path, Express can remove that mount prefix from the value.

Example: Read the request URL

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

app.get('/inspect', (req, res) => {
  res.json({ url: req.url });
});

app.listen(3000);

Run the app and request /inspect?mode=full to return the request URL, including its query string.

When to use it

Request inspection

Inspect the incoming path and query string in a route or middleware.

Internal middleware routing

Route or transform a request after middleware has adjusted its internal URL.

Interview questions

QWhat is req.url in Express?

req.url is the request URL exposed on the request object. In Express, it is inherited from Node's HTTP module rather than being an Express-native property.

Follow-up: How can middleware preserve the URL before Express rewrites it? Use req.originalUrl, which retains the original request URL.

QCan req.url change during request processing?

Mounted middleware can cause req.url to change because Express strips the mount point when dispatching through app.use(). Therefore, code inside mounted middleware may see a shorter URL than the client sent.

Follow-up: What property should be used when the original URL is required? Use req.originalUrl, which preserves the request URL before internal rewriting.

QDoes req.url include the query string?

req.url can include the path and query string, so a request such as /search?q=something exposes that complete URL value through the request object. It is useful when middleware needs the raw request URL representation.

Follow-up: How can the query component be handled separately? Use Express's documented query-related request property or query parsing facilities rather than manually splitting the URL.

  • req.originalUrl
  • req.baseUrl
  • req.path
  • req.query
  • app.use()

Source: Request Object - Express.js 4.x. Checked 2026-10-15.