URL
URL.parse()
Returns a WHATWG URL or null for a parse failure. Validate scheme and destination separately when designing outbound requests. Tested on Node.js 22.16.0. Example output (one line per entry): ["/books true"].
Formal Syntax & Structure
nodejs syntaxnodejs
URL.parse(input[, base])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| input | string | URL input. |
| base | string | URL | Optional base. |
Return Value
URL | null
Parsed URL or null.
Working Example
Example Snippetnodejs
console.log(URL.parse('/books', 'https://example.invalid').pathname, URL.parse('/books') === null);