HTTP
request.url
Provides the request-target string seen by the server, including its query when present. Parse against a fixed trusted base for an origin-form request; do not assume the value or Host header is a trusted outbound URL. Tested on Node.js 22.16.0. Example output (one line per entry): ["/books 3"].
Formal Syntax & Structure
nodejs syntaxnodejs
request.urlReturn Value
string
Request-target for the incoming request.
Working Example
Example Snippetnodejs
import http from 'node:http';const server = http.createServer((req, res) => { const u = new URL(req.url, 'http://fixture.invalid'); res.end(u.pathname + ' ' + u.searchParams.get('page')); });await new Promise(r => server.listen(0, '127.0.0.1', r));const url = 'http://127.0.0.1:' + server.address().port;try { console.log(await (await fetch(url + '/books?page=3')).text());}finally { server.closeAllConnections(); await new Promise(r => server.close(r));}