node:url

Legacy Node.js URL helpers and WHATWG URL re-exports

node:url supplies Node’s legacy URL helpers alongside the global URL and URLSearchParams constructors.

const url = require("node:url");
const parsed = url.parse("https://user:pw@example.com:8080/a?x=1#h", true);
parsed.host;    // "example.com:8080"
parsed.query.x; // "1"

url.resolve("https://example.com/a/b/c", "../x");
// "https://example.com/a/x"
HelperResult
parse(value, parseQueryString?, slashesDenoteHost?)A legacy UrlObject; parsed duplicate keys become arrays.
format(value)A string built from a legacy object or WHATWG URL.
resolve(from, to)A resolved URL string.
resolveObject(from, to)A resolved legacy object.
domainToASCII() / domainToUnicode()IDN conversion.
fileURLToPath() / pathToFileURL()File URL and absolute path conversion.
urlToHttpOptions()Options for Node HTTP request APIs.

url.URL === globalThis.URL and url.URLSearchParams === globalThis.URLSearchParams. New code should prefer these WHATWG constructors over the legacy parser.

See also