Express.js req.originalUrl Property

Beginner
5 min read
Updated: Nov 2026
3 examples
Request

Definition

req.originalUrl is a string with the original request URL (path + query). It stays stable when Express rewrites req.url for mounting with app.use().

Use it for logging, audits, and redirects that must reflect what the client actually asked for. Inside a mounted stack it lines up with req.baseUrl plus req.url. For the path alone (no query), see req.path.

Syntax

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

Express
req.originalUrl
CallWhat it does
req.originalUrlPrimary signature.

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.originalUrl

Parameters

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

Return Value

req.originalUrl is a string: the original request URL path plus query string. It is not a full absolute URL with scheme and host.

Express
// GET /admin/users?active=1  (mounted or rewritten paths may differ on req.url)
req.originalUrl; // '/admin/users?active=1'

Express.js Examples

Example 1 — Log the Original URL

Record the full path and query for every request (official basic form).

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

app.use((req, res, next) => {
  // GET /search?q=something
  console.dir(req.originalUrl);
  // => '/search?q=something'
  next();
});

app.get('/search', (req, res) => {
  res.send('ok');
});

app.listen(3000);

How It Works

  1. Middleware runs first. Every request hits the logger before routes.
  2. Read originalUrl. Path and query stay together in one string.
  3. Call next(). Logging must not end the chain.
  4. Route answers. app.get('/search') sends the response afterward.

Example 2 — Values Inside a Mount

Same numbers as the Express docs: mount at /admin and inspect the split.

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

// GET http://www.example.com/admin/new?sort=desc
app.use('/admin', (req, res, next) => {
  console.dir(req.originalUrl); // '/admin/new?sort=desc'
  console.dir(req.baseUrl);     // '/admin'
  console.dir(req.path);        // '/new'
  next();
});

app.get('/admin/new', (req, res) => {
  res.send('admin new');
});

app.listen(3000);

How It Works

  1. Mount strips the prefix for routing. app.use('/admin', …) rewrites req.url.
  2. originalUrl stays whole. Still /admin/new?sort=desc.
  3. baseUrl is the mount. Here /admin.
  4. path is the remainder path. /new without the query.

Example 3 — Compare Values in a Router

Return JSON from a mounted Router so you can see all three at once.

Express
const express = require('express');
const app = express();
const admin = express.Router();

admin.get('/users', (req, res) => {
  res.json({
    originalUrl: req.originalUrl, // /admin/users?active=true
    url: req.url,                 // /users?active=true
    baseUrl: req.baseUrl,         // /admin
    path: req.path                // /users
  });
});

app.use('/admin', admin);
app.listen(3000);

How It Works

  1. Create a router. Routes are defined relative to the mount.
  2. Mount at /admin. Express rewrites req.url for that stack.
  3. Handler sees the split. url/path are relative; originalUrl is not.
  4. JSON makes it obvious. Compare fields side by side in the response.

Runtime Support

req.originalUrl is an Express.js request property. It runs on a Node.js server (Express 5 needs Node.js 18+). Browsers do not execute it — they only send HTTP requests to your app.

✓ Server · Express 4 & 5

req.originalUrl

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.originalUrl 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 a string with the original request URL path plus query string, kept even when Express rewrites req.url for mounting.
req.url can be rewritten when you mount middleware or routers (the mount prefix is stripped). req.originalUrl stays as the client originally requested.
Yes. For GET /search?q=something, req.originalUrl is '/search?q=something'.
Inside a mounted stack, req.originalUrl is effectively the combination of req.baseUrl and req.url. req.path is the path part without the query.
No. It is a server-side Express request property. Browsers only send the HTTP request; your app reads originalUrl on the server.

Next: req.params

Read named route parameters like /users/:id.

req.params 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