Skip to content

node:url

How Elide supports Node's url module: legacy parse, format and resolve, file-URL helpers, and the global URL, URLSearchParams and URLPattern classes.

On this page

node:url matches Node’s url: legacy parse, format, and resolve plus file-URL helpers; its URL, URLSearchParams, and URLPattern are the global URL, URLSearchParams, and URLPattern.

Example

js
// url.mjs
import { fileURLToPath, format, pathToFileURL } from "node:url";

console.log(pathToFileURL("/tmp/report 1.txt").href);
console.log(fileURLToPath("file:///tmp/report%201.txt"));
console.log(format(new URL("https://user:pw@example.com/a?b=1#top"), { auth: false, fragment: false }));
utf-8 · js · Lines: 6

elide run url.mjs prints:

text
file:///tmp/report%201.txt
/tmp/report 1.txt
https://example.com/a?b=1
utf-8 · text · Lines: 3

Reference

Status: Full · 40 of 42 suite tests pass (95.2%) · since 1.1.0

Exports

ExportKindStatusNotes
parse()functionFullParses a URL string into a UrlObject (legacy API)
format()functionFullFormats a URL object or WHATWG URL back into a string
resolve()functionFullResolves a target URL relative to a base URL (legacy API)
URLpropertyFullThe WHATWG URL class (same as global URL)
URLSearchParamspropertyFullThe WHATWG URLSearchParams class (same as global URLSearchParams)
domainToASCII()functionFullConverts a Unicode domain name to its ASCII (Punycode) representation
domainToUnicode()functionFullConverts an ASCII (Punycode) domain name to Unicode
fileURLToPath()functionFullConverts a file: URL to a filesystem path string
pathToFileURL()functionFullConverts an absolute filesystem path to a file: URL
urlToHttpOptions()functionFullReturns an object with URL components suitable for use with http.request()
resolveObject()functionFullResolves a relative URL against a source URL object, similar to a browser resolving an anchor tag

Tests: node-api node:url: 40 pass, 2 fail, 0 error, 3 skipped. Failing: test-whatwg-url-custom-inspect.js, test-whatwg-url-custom-parsing.js.

Was this page helpful?