URL
new URL()
Parses an absolute URL or resolves a relative reference against a base. Tested on Node.js 22.16.0. Parsing does not make a URL safe for server-side fetching; separately authorize scheme and destination.
Formal Syntax & Structure
nodejs syntaxnodejs
new URL(input[, base])Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| input | string | URL text. |
| base | string | Base URL for relative input. |
Return Value
URL
Parsed URL object.
Working Example
Example Snippetnodejs
import { URL, URLSearchParams, fileURLToPath, pathToFileURL } from 'node:url';const u=new URL('../book?edition=2','https://example.com/catalog/');console.log(u.pathname,u.search);