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

NameTypeDescription
inputstringURL input.
basestring | URLOptional 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);
Node.js Reference