URL
Node.js url module — URL parsing and formatting utilities. Exposes both the legacy API (parse/format/resolve) and the WHATWG URL class.
Module:node:url
Support: Experimental
Since: 1.1.0
Docs: Node.js Docs
11 members: 10 supported, 1 undocumented
Static Methods
Properties
---
Details
parse(urlString, parseQueryString, slashesDenoteHost)
static parse(urlString: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): UrlObject
static parse(urlString: string, parseQueryString?: boolean, slashesDenoteHost?: boolean): UrlObject
Parses a URL string into a UrlObject (legacy API).| Parameter | Type | Description |
|---|---|---|
urlString | string | The URL string to parse |
parseQueryString (optional) | boolean | If true, the query property is parsed into an object |
slashesDenoteHost (optional) | boolean | If true, //foo/bar treats foo as the host |
> Known issue: Legacy API; prefer the WHATWG URL constructor for new code
resolve(from, to)
static resolve(from: string, to: string): string
static resolve(from: string, to: string): string
Resolves a target URL relative to a base URL (legacy API).| Parameter | Type | Description |
|---|---|---|
from | string | The base URL string |
to | string | The target URL string |
> Known issue: Legacy API; prefer the WHATWG URL constructor with a base argument
fileURLToPath(url)
static fileURLToPath(url: (string or URL)): string
static fileURLToPath(url: (string or URL)): string
Converts a file: URL to a filesystem path string.| Parameter | Type | Description |
|---|---|---|
url | (string or URL) | A file: URL string or WHATWG URL object |
TypeError--- If the URL is not a file: URL
resolveObject(source, relative)
static resolveObject(source: (string or UrlObject), relative: string): UrlObject
static resolveObject(source: (string or UrlObject), relative: string): UrlObject
Resolves a relative URL against a source URL object, similar to a browser resolving an anchor tag.| Parameter | Type | Description |
|---|---|---|
source | (string or UrlObject) | The base URL string or UrlObject to resolve from |
relative | string | The relative URL string to resolve |
> Known issue: Legacy API; prefer the WHATWG URL constructor with a base argument
Dictionary UrlObject
Structured representation of a parsed URL from the legacy url.parse() API.
Since: 1.1.0 Docs: Node.js Docs12 members: 2 supported, 10 undocumented
Properties
---