Errors

ERR_INVALID_URL

The URL constructor cannot parse its input and base. Supply an explicit base for relative references and validate destination separately. Tested on Node.js 22.16.0. Example output (one line per entry): ["ERR_INVALID_URL", "/books"].

Formal Syntax & Structure

nodejs syntaxnodejs
error.code === "ERR_INVALID_URL"

Return Value

Error

Observed error classification; successful correction has its own return value.

Working Example

Example Snippetnodejs
try {    new URL('/books');}catch (e) {    console.log(e.code);}console.log(new URL('/books', 'https://example.invalid').pathname);
Node.js Reference