URL
URL.canParse()
Checks whether a URL can be parsed without throwing. A parseable URL is not necessarily safe to fetch. Tested on Node.js 22.16.0. Example output (one line per entry): ["true false"].
Formal Syntax & Structure
nodejs syntaxnodejs
URL.canParse(input[, base])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| input | string | URL input. |
| base | string | URL | Base for relative input. |
Return Value
boolean
Parse success.
Working Example
Example Snippetnodejs
console.log(URL.canParse('/books', 'https://example.invalid'), URL.canParse('/books'));