Request inspection
Inspect the incoming path and query string in a route or middleware.
Express.js · Pipe
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.
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.
req.urlString
req.url is accessed from Express's request object inside handlers and middleware.req.originalUrl property is the option for retaining the unmodified URL.req.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.
Inspect the incoming path and query string in a route or middleware.
Route or transform a request after middleware has adjusted its internal URL.
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.
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.
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.originalUrlreq.baseUrlreq.pathreq.queryapp.use()