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

NameTypeDescription
inputstringURL input.
basestring | URLBase for relative input.

Return Value

boolean

Parse success.

Working Example

Example Snippetnodejs
console.log(URL.canParse('/books', 'https://example.invalid'), URL.canParse('/books'));
Node.js Reference