{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"url","path":"/url","type":"module","module":"url","title":"URL","introducedIn":"v0.10.0","sourceLink":{"path":"lib/url.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/url.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `node:url` module provides utilities for URL resolution and parsing. It can\nbe accessed using:\n\n```mjs\nimport url from 'node:url';\n```\n\n```cjs\nconst url = require('node:url');\n```","summary":"The `node:url` module provides utilities for URL resolution and parsing. It can be accessed using:","examples":[{"language":"mjs","displayName":null,"code":"import url from 'node:url';"},{"language":"cjs","displayName":null,"code":"const url = require('node:url');"}],"children":[{"kind":"section","id":"url-strings-and-url-objects","name":"URL strings and URL objects","title":"URL strings and URL objects","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"A URL string is a structured string containing multiple meaningful components.\nWhen parsed, a URL object is returned containing properties for each of these\ncomponents.\n\nThe `node:url` module provides two APIs for working with URLs: a legacy API that\nis Node.js specific, and a newer API that implements the same\n[WHATWG URL Standard](https://url.spec.whatwg.org/) used by web browsers.\n\nA comparison between the WHATWG and legacy APIs is provided below. Above the URL\n`'https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'`, properties\nof an object returned by the legacy `url.parse()` are shown. Below it are\nproperties of a WHATWG `URL` object.\n\nWHATWG URL's `origin` property includes `protocol` and `host`, but not\n`username` or `password`.\n\n```text\n┌────────────────────────────────────────────────────────────────────────────────────────────────┐\n│                                              href                                              │\n├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤\n│ protocol │  │        auth         │          host          │           path            │ hash  │\n│          │  │                     ├─────────────────┬──────┼──────────┬────────────────┤       │\n│          │  │                     │    hostname     │ port │ pathname │     search     │       │\n│          │  │                     │                 │      │          ├─┬──────────────┤       │\n│          │  │                     │                 │      │          │ │    query     │       │\n\"  https:   //    user   :   pass   @ sub.example.com : 8080   /p/a/t/h  ?  query=string   #hash \"\n│          │  │          │          │    hostname     │ port │          │                │       │\n│          │  │          │          ├─────────────────┴──────┤          │                │       │\n│ protocol │  │ username │ password │          host          │          │                │       │\n├──────────┴──┼──────────┴──────────┼────────────────────────┤          │                │       │\n│   origin    │                     │         origin         │ pathname │     search     │ hash  │\n├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤\n│                                              href                                              │\n└────────────────────────────────────────────────────────────────────────────────────────────────┘\n(All spaces in the \"\" line should be ignored. They are purely for formatting.)\n```\n\nParsing the URL string using the WHATWG API:\n\n```js\nconst myURL =\n  new URL('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');\n```\n\nParsing the URL string using the legacy API:\n\n```mjs\nimport url from 'node:url';\nconst myURL =\n  url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');\n```\n\n```cjs\nconst url = require('node:url');\nconst myURL =\n  url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');\n```","summary":"A URL string is a structured string containing multiple meaningful components. When parsed, a URL object is returned containing properties for each of these components.","examples":[{"language":"text","displayName":null,"code":"┌────────────────────────────────────────────────────────────────────────────────────────────────┐\n│                                              href                                              │\n├──────────┬──┬─────────────────────┬────────────────────────┬───────────────────────────┬───────┤\n│ protocol │  │        auth         │          host          │           path            │ hash  │\n│          │  │                     ├─────────────────┬──────┼──────────┬────────────────┤       │\n│          │  │                     │    hostname     │ port │ pathname │     search     │       │\n│          │  │                     │                 │      │          ├─┬──────────────┤       │\n│          │  │                     │                 │      │          │ │    query     │       │\n\"  https:   //    user   :   pass   @ sub.example.com : 8080   /p/a/t/h  ?  query=string   #hash \"\n│          │  │          │          │    hostname     │ port │          │                │       │\n│          │  │          │          ├─────────────────┴──────┤          │                │       │\n│ protocol │  │ username │ password │          host          │          │                │       │\n├──────────┴──┼──────────┴──────────┼────────────────────────┤          │                │       │\n│   origin    │                     │         origin         │ pathname │     search     │ hash  │\n├─────────────┴─────────────────────┴────────────────────────┴──────────┴────────────────┴───────┤\n│                                              href                                              │\n└────────────────────────────────────────────────────────────────────────────────────────────────┘\n(All spaces in the \"\" line should be ignored. They are purely for formatting.)"},{"language":"js","displayName":null,"code":"const myURL =\n  new URL('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');"},{"language":"mjs","displayName":null,"code":"import url from 'node:url';\nconst myURL =\n  url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');"},{"language":"cjs","displayName":null,"code":"const url = require('node:url');\nconst myURL =\n  url.parse('https://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash');"}],"children":[{"kind":"section","id":"constructing-a-url-from-component-parts-and-getting-the-constructed-string","name":"Constructing a URL from component parts and getting the constructed string","title":"Constructing a URL from component parts and getting the constructed string","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"It is possible to construct a WHATWG URL from component parts using either the\nproperty setters or a template literal string:\n\n```js\nconst myURL = new URL('https://example.org');\nmyURL.pathname = '/a/b/c';\nmyURL.search = '?d=e';\nmyURL.hash = '#fgh';\n```\n\n```js\nconst pathname = '/a/b/c';\nconst search = '?d=e';\nconst hash = '#fgh';\nconst myURL = new URL(`https://example.org${pathname}${search}${hash}`);\n```\n\nTo get the constructed URL string, use the `href` property accessor:\n\n```js\nconsole.log(myURL.href);\n```","summary":"It is possible to construct a WHATWG URL from component parts using either the property setters or a template literal string:","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org');\nmyURL.pathname = '/a/b/c';\nmyURL.search = '?d=e';\nmyURL.hash = '#fgh';"},{"language":"js","displayName":null,"code":"const pathname = '/a/b/c';\nconst search = '?d=e';\nconst hash = '#fgh';\nconst myURL = new URL(`https://example.org${pathname}${search}${hash}`);"},{"language":"js","displayName":null,"code":"console.log(myURL.href);"}],"children":[]}]},{"kind":"section","id":"the-whatwg-url-api","name":"The WHATWG URL API","title":"The WHATWG URL API","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"","summary":"","examples":[],"children":[{"kind":"class","id":"class-url","name":"URL","title":"Class: `URL`","scope":"module","overloadOf":null,"stability":null,"added":["v7.0.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/18281","commit":null,"description":"The class is now available on the global object."}],"extends":null,"description":"Browser-compatible `URL` class, implemented by following the WHATWG URL\nStandard. [Examples of parsed URLs](https://url.spec.whatwg.org/#example-url-parsing) may be found in the Standard itself.\nThe `URL` class is also available on the global object.\n\nIn accordance with browser conventions, all properties of `URL` objects\nare implemented as getters and setters on the class prototype, rather than as\ndata properties on the object itself. Thus, unlike [legacy `urlObject`](#legacy-urlobject)s,\nusing the `delete` keyword on any properties of `URL` objects (e.g. `delete\nmyURL.protocol`, `delete myURL.pathname`, etc) has no effect but will still\nreturn `true`.","summary":"Browser-compatible `URL` class, implemented by following the WHATWG URL Standard. Examples of parsed URLs may be found in the Standard itself. The `URL` class is also available on the global object.","examples":[],"children":[{"kind":"constructor","id":"new-urlinput-base","name":"URL","title":"`new URL(input[, base])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.0.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/47339","commit":null,"description":"ICU requirement is removed."}],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The absolute or relative input URL to parse. If `input`\nis relative, then `base` is required. If `input` is absolute, the `base`\nis ignored. If `input` is not a string, it is [converted to a string](https://tc39.es/ecma262/#sec-tostring) first.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"base","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The base URL to resolve against if the `input` is not\nabsolute. If `base` is not a string, it is [converted to a string](https://tc39.es/ecma262/#sec-tostring) first.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Creates a new `URL` object by parsing the `input` relative to the `base`. If\n`base` is passed as a string, it will be parsed equivalent to `new URL(base)`.\n\n```js\nconst myURL = new URL('/foo', 'https://example.org/');\n// https://example.org/foo\n```\n\nThe URL constructor is accessible as a property on the global object.\nIt can also be imported from the built-in url module:\n\n```mjs\nimport { URL } from 'node:url';\nconsole.log(URL === globalThis.URL); // Prints 'true'.\n```\n\n```cjs\nconsole.log(URL === require('node:url').URL); // Prints 'true'.\n```\n\nA `TypeError` will be thrown if the `input` or `base` are not valid URLs. Note\nthat an effort will be made to coerce the given values into strings. For\ninstance:\n\n```js\nconst myURL = new URL({ toString: () => 'https://example.org/' });\n// https://example.org/\n```\n\nUnicode characters appearing within the host name of `input` will be\nautomatically converted to ASCII using the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) algorithm.\n\n```js\nconst myURL = new URL('https://測試');\n// https://xn--g6w251d/\n```\n\nIn cases where it is not known in advance if `input` is an absolute URL\nand a `base` is provided, it is advised to validate that the `origin` of\nthe `URL` object is what is expected.\n\n```js\nlet myURL = new URL('http://Example.com/', 'https://example.org/');\n// http://example.com/\n\nmyURL = new URL('https://Example.com/', 'https://example.org/');\n// https://example.com/\n\nmyURL = new URL('foo://Example.com/', 'https://example.org/');\n// foo://Example.com/\n\nmyURL = new URL('http:Example.com/', 'https://example.org/');\n// http://example.com/\n\nmyURL = new URL('https:Example.com/', 'https://example.org/');\n// https://example.org/Example.com/\n\nmyURL = new URL('foo:Example.com/', 'https://example.org/');\n// foo:Example.com/\n```","summary":"Creates a new `URL` object by parsing the `input` relative to the `base`. If `base` is passed as a string, it will be parsed equivalent to `new URL(base)`.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('/foo', 'https://example.org/');\n// https://example.org/foo"},{"language":"mjs","displayName":null,"code":"import { URL } from 'node:url';\nconsole.log(URL === globalThis.URL); // Prints 'true'."},{"language":"cjs","displayName":null,"code":"console.log(URL === require('node:url').URL); // Prints 'true'."},{"language":"js","displayName":null,"code":"const myURL = new URL({ toString: () => 'https://example.org/' });\n// https://example.org/"},{"language":"js","displayName":null,"code":"const myURL = new URL('https://測試');\n// https://xn--g6w251d/"},{"language":"js","displayName":null,"code":"let myURL = new URL('http://Example.com/', 'https://example.org/');\n// http://example.com/\n\nmyURL = new URL('https://Example.com/', 'https://example.org/');\n// https://example.com/\n\nmyURL = new URL('foo://Example.com/', 'https://example.org/');\n// foo://Example.com/\n\nmyURL = new URL('http:Example.com/', 'https://example.org/');\n// http://example.com/\n\nmyURL = new URL('https:Example.com/', 'https://example.org/');\n// https://example.org/Example.com/\n\nmyURL = new URL('foo:Example.com/', 'https://example.org/');\n// foo:Example.com/"}],"children":[]},{"kind":"property","id":"urlhash","name":"hash","title":"`url.hash`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the fragment portion of the URL.\n\n```js\nconst myURL = new URL('https://example.org/foo#bar');\nconsole.log(myURL.hash);\n// Prints #bar\n\nmyURL.hash = 'baz';\nconsole.log(myURL.href);\n// Prints https://example.org/foo#baz\n```\n\nInvalid URL characters included in the value assigned to the `hash` property\nare [percent-encoded](#percent-encoding-in-urls). The selection of which characters to\npercent-encode may vary somewhat from what the [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost) and\n[`url.format()`](#urlformaturlobject) methods would produce.","summary":"Gets and sets the fragment portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/foo#bar');\nconsole.log(myURL.hash);\n// Prints #bar\n\nmyURL.hash = 'baz';\nconsole.log(myURL.href);\n// Prints https://example.org/foo#baz"}],"children":[]},{"kind":"property","id":"urlhost","name":"host","title":"`url.host`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the host portion of the URL.\n\n```js\nconst myURL = new URL('https://example.org:81/foo');\nconsole.log(myURL.host);\n// Prints example.org:81\n\nmyURL.host = 'example.com:82';\nconsole.log(myURL.href);\n// Prints https://example.com:82/foo\n```\n\nInvalid host values assigned to the `host` property are ignored.","summary":"Gets and sets the host portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org:81/foo');\nconsole.log(myURL.host);\n// Prints example.org:81\n\nmyURL.host = 'example.com:82';\nconsole.log(myURL.href);\n// Prints https://example.com:82/foo"}],"children":[]},{"kind":"property","id":"urlhostname","name":"hostname","title":"`url.hostname`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the host name portion of the URL. The key difference between\n`url.host` and `url.hostname` is that `url.hostname` does *not* include the\nport.\n\n```js\nconst myURL = new URL('https://example.org:81/foo');\nconsole.log(myURL.hostname);\n// Prints example.org\n\n// Setting the hostname does not change the port\nmyURL.hostname = 'example.com';\nconsole.log(myURL.href);\n// Prints https://example.com:81/foo\n\n// Use myURL.host to change the hostname and port\nmyURL.host = 'example.org:82';\nconsole.log(myURL.href);\n// Prints https://example.org:82/foo\n```\n\nInvalid host name values assigned to the `hostname` property are ignored.","summary":"Gets and sets the host name portion of the URL. The key difference between `url.host` and `url.hostname` is that `url.hostname` does _not_ include the port.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org:81/foo');\nconsole.log(myURL.hostname);\n// Prints example.org\n\n// Setting the hostname does not change the port\nmyURL.hostname = 'example.com';\nconsole.log(myURL.href);\n// Prints https://example.com:81/foo\n\n// Use myURL.host to change the hostname and port\nmyURL.host = 'example.org:82';\nconsole.log(myURL.href);\n// Prints https://example.org:82/foo"}],"children":[]},{"kind":"property","id":"urlhref","name":"href","title":"`url.href`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the serialized URL.\n\n```js\nconst myURL = new URL('https://example.org/foo');\nconsole.log(myURL.href);\n// Prints https://example.org/foo\n\nmyURL.href = 'https://example.com/bar';\nconsole.log(myURL.href);\n// Prints https://example.com/bar\n```\n\nGetting the value of the `href` property is equivalent to calling\n[`url.toString()`](#urltostring).\n\nSetting the value of this property to a new value is equivalent to creating a\nnew `URL` object using [`new URL(value)`](#new-urlinput-base). Each of the `URL`\nobject's properties will be modified.\n\nIf the value assigned to the `href` property is not a valid URL, a `TypeError`\nwill be thrown.","summary":"Gets and sets the serialized URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/foo');\nconsole.log(myURL.href);\n// Prints https://example.org/foo\n\nmyURL.href = 'https://example.com/bar';\nconsole.log(myURL.href);\n// Prints https://example.com/bar"}],"children":[]},{"kind":"property","id":"urlorigin","name":"origin","title":"`url.origin`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33325","commit":null,"description":"The scheme \"gopher\" is no longer special and `url.origin` now returns `'null'` for it."}],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets the read-only serialization of the URL's origin.\n\n```js\nconst myURL = new URL('https://example.org/foo/bar?baz');\nconsole.log(myURL.origin);\n// Prints https://example.org\n```\n\n```js\nconst idnURL = new URL('https://測試');\nconsole.log(idnURL.origin);\n// Prints https://xn--g6w251d\n\nconsole.log(idnURL.hostname);\n// Prints xn--g6w251d\n```","summary":"Gets the read-only serialization of the URL's origin.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/foo/bar?baz');\nconsole.log(myURL.origin);\n// Prints https://example.org"},{"language":"js","displayName":null,"code":"const idnURL = new URL('https://測試');\nconsole.log(idnURL.origin);\n// Prints https://xn--g6w251d\n\nconsole.log(idnURL.hostname);\n// Prints xn--g6w251d"}],"children":[]},{"kind":"property","id":"urlpassword","name":"password","title":"`url.password`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the password portion of the URL.\n\n```js\nconst myURL = new URL('https://abc:xyz@example.com');\nconsole.log(myURL.password);\n// Prints xyz\n\nmyURL.password = '123';\nconsole.log(myURL.href);\n// Prints https://abc:123@example.com/\n```\n\nInvalid URL characters included in the value assigned to the `password` property\nare [percent-encoded](#percent-encoding-in-urls). The selection of which characters to\npercent-encode may vary somewhat from what the [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost) and\n[`url.format()`](#urlformaturlobject) methods would produce.","summary":"Gets and sets the password portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://abc:xyz@example.com');\nconsole.log(myURL.password);\n// Prints xyz\n\nmyURL.password = '123';\nconsole.log(myURL.href);\n// Prints https://abc:123@example.com/"}],"children":[]},{"kind":"property","id":"urlpathname","name":"pathname","title":"`url.pathname`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the path portion of the URL.\n\n```js\nconst myURL = new URL('https://example.org/abc/xyz?123');\nconsole.log(myURL.pathname);\n// Prints /abc/xyz\n\nmyURL.pathname = '/abcdef';\nconsole.log(myURL.href);\n// Prints https://example.org/abcdef?123\n```\n\nInvalid URL characters included in the value assigned to the `pathname`\nproperty are [percent-encoded](#percent-encoding-in-urls). The selection of which characters\nto percent-encode may vary somewhat from what the [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost) and\n[`url.format()`](#urlformaturlobject) methods would produce.","summary":"Gets and sets the path portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/abc/xyz?123');\nconsole.log(myURL.pathname);\n// Prints /abc/xyz\n\nmyURL.pathname = '/abcdef';\nconsole.log(myURL.href);\n// Prints https://example.org/abcdef?123"}],"children":[]},{"kind":"property","id":"urlport","name":"port","title":"`url.port`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33325","commit":null,"description":"The scheme \"gopher\" is no longer special."}],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the port portion of the URL.\n\nThe port value may be a number or a string containing a number in the range\n`0` to `65535` (inclusive). Setting the value to the default port of the\n`URL` objects given `protocol` will result in the `port` value becoming\nthe empty string (`''`).\n\nThe port value can be an empty string in which case the port depends on\nthe protocol/scheme:\n\n| protocol | port |\n| -------- | ---- |\n| \"ftp\"    | 21   |\n| \"file\"   |      |\n| \"http\"   | 80   |\n| \"https\"  | 443  |\n| \"ws\"     | 80   |\n| \"wss\"    | 443  |\n\nUpon assigning a value to the port, the value will first be converted to a\nstring using `.toString()`.\n\nIf that string is invalid but it begins with a number, the leading number is\nassigned to `port`.\nIf the number lies outside the range denoted above, it is ignored.\n\n```js\nconst myURL = new URL('https://example.org:8888');\nconsole.log(myURL.port);\n// Prints 8888\n\n// Default ports are automatically transformed to the empty string\n// (HTTPS protocol's default port is 443)\nmyURL.port = '443';\nconsole.log(myURL.port);\n// Prints the empty string\nconsole.log(myURL.href);\n// Prints https://example.org/\n\nmyURL.port = 1234;\nconsole.log(myURL.port);\n// Prints 1234\nconsole.log(myURL.href);\n// Prints https://example.org:1234/\n\n// Completely invalid port strings are ignored\nmyURL.port = 'abcd';\nconsole.log(myURL.port);\n// Prints 1234\n\n// Leading numbers are treated as a port number\nmyURL.port = '5678abcd';\nconsole.log(myURL.port);\n// Prints 5678\n\n// Non-integers are truncated\nmyURL.port = 1234.5678;\nconsole.log(myURL.port);\n// Prints 1234\n\n// Out-of-range numbers which are not represented in scientific notation\n// will be ignored.\nmyURL.port = 1e10; // 10000000000, will be range-checked as described below\nconsole.log(myURL.port);\n// Prints 1234\n```\n\nNumbers which contain a decimal point,\nsuch as floating-point numbers or numbers in scientific notation,\nare not an exception to this rule.\nLeading numbers up to the decimal point will be set as the URL's port,\nassuming they are valid:\n\n```js\nmyURL.port = 4.567e21;\nconsole.log(myURL.port);\n// Prints 4 (because it is the leading number in the string '4.567e21')\n```","summary":"Gets and sets the port portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org:8888');\nconsole.log(myURL.port);\n// Prints 8888\n\n// Default ports are automatically transformed to the empty string\n// (HTTPS protocol's default port is 443)\nmyURL.port = '443';\nconsole.log(myURL.port);\n// Prints the empty string\nconsole.log(myURL.href);\n// Prints https://example.org/\n\nmyURL.port = 1234;\nconsole.log(myURL.port);\n// Prints 1234\nconsole.log(myURL.href);\n// Prints https://example.org:1234/\n\n// Completely invalid port strings are ignored\nmyURL.port = 'abcd';\nconsole.log(myURL.port);\n// Prints 1234\n\n// Leading numbers are treated as a port number\nmyURL.port = '5678abcd';\nconsole.log(myURL.port);\n// Prints 5678\n\n// Non-integers are truncated\nmyURL.port = 1234.5678;\nconsole.log(myURL.port);\n// Prints 1234\n\n// Out-of-range numbers which are not represented in scientific notation\n// will be ignored.\nmyURL.port = 1e10; // 10000000000, will be range-checked as described below\nconsole.log(myURL.port);\n// Prints 1234"},{"language":"js","displayName":null,"code":"myURL.port = 4.567e21;\nconsole.log(myURL.port);\n// Prints 4 (because it is the leading number in the string '4.567e21')"}],"children":[]},{"kind":"property","id":"urlprotocol","name":"protocol","title":"`url.protocol`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the protocol portion of the URL.\n\n```js\nconst myURL = new URL('https://example.org');\nconsole.log(myURL.protocol);\n// Prints https:\n\nmyURL.protocol = 'ftp';\nconsole.log(myURL.href);\n// Prints ftp://example.org/\n```\n\nInvalid URL protocol values assigned to the `protocol` property are ignored.","summary":"Gets and sets the protocol portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org');\nconsole.log(myURL.protocol);\n// Prints https:\n\nmyURL.protocol = 'ftp';\nconsole.log(myURL.href);\n// Prints ftp://example.org/"}],"children":[{"kind":"section","id":"special-schemes","name":"Special schemes","title":"Special schemes","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33325","commit":null,"description":"The scheme \"gopher\" is no longer special."}],"description":"The [WHATWG URL Standard](https://url.spec.whatwg.org/) considers a handful of URL protocol schemes to be\n*special* in terms of how they are parsed and serialized. When a URL is\nparsed using one of these special protocols, the `url.protocol` property\nmay be changed to another special protocol but cannot be changed to a\nnon-special protocol, and vice versa.\n\nFor instance, changing from `http` to `https` works:\n\n```js\nconst u = new URL('http://example.org');\nu.protocol = 'https';\nconsole.log(u.href);\n// https://example.org/\n```\n\nHowever, changing from `http` to a hypothetical `fish` protocol does not\nbecause the new protocol is not special.\n\n```js\nconst u = new URL('http://example.org');\nu.protocol = 'fish';\nconsole.log(u.href);\n// http://example.org/\n```\n\nLikewise, changing from a non-special protocol to a special protocol is also\nnot permitted:\n\n```js\nconst u = new URL('fish://example.org');\nu.protocol = 'http';\nconsole.log(u.href);\n// fish://example.org\n```\n\nAccording to the WHATWG URL Standard, special protocol schemes are `ftp`,\n`file`, `http`, `https`, `ws`, and `wss`.","summary":"The WHATWG URL Standard considers a handful of URL protocol schemes to be _special_ in terms of how they are parsed and serialized. When a URL is parsed using one of these special protocols, the `url.protocol` property may be changed to another special protocol but cannot be changed to a non-special protocol, and vice versa.","examples":[{"language":"js","displayName":null,"code":"const u = new URL('http://example.org');\nu.protocol = 'https';\nconsole.log(u.href);\n// https://example.org/"},{"language":"js","displayName":null,"code":"const u = new URL('http://example.org');\nu.protocol = 'fish';\nconsole.log(u.href);\n// http://example.org/"},{"language":"js","displayName":null,"code":"const u = new URL('fish://example.org');\nu.protocol = 'http';\nconsole.log(u.href);\n// fish://example.org"}],"children":[]}]},{"kind":"property","id":"urlsearch","name":"search","title":"`url.search`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the serialized query portion of the URL.\n\n```js\nconst myURL = new URL('https://example.org/abc?123');\nconsole.log(myURL.search);\n// Prints ?123\n\nmyURL.search = 'abc=xyz';\nconsole.log(myURL.href);\n// Prints https://example.org/abc?abc=xyz\n```\n\nAny invalid URL characters appearing in the value assigned the `search`\nproperty will be [percent-encoded](#percent-encoding-in-urls). The selection of which\ncharacters to percent-encode may vary somewhat from what the [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost)\nand [`url.format()`](#urlformaturlobject) methods would produce.","summary":"Gets and sets the serialized query portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/abc?123');\nconsole.log(myURL.search);\n// Prints ?123\n\nmyURL.search = 'abc=xyz';\nconsole.log(myURL.href);\n// Prints https://example.org/abc?abc=xyz"}],"children":[]},{"kind":"property","id":"urlsearchparams","name":"searchParams","title":"`url.searchParams`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"URLSearchParams","links":[{"name":"URLSearchParams","href":"url.html#class-urlsearchparams","start":0,"end":15}]},"default":null,"description":"Gets the [`URLSearchParams`](#class-urlsearchparams) object representing the query parameters of the\nURL. This property is read-only but the `URLSearchParams` object it provides\ncan be used to mutate the URL instance; to replace the entirety of query\nparameters of the URL, use the [`url.search`](#urlsearch) setter. See\n[`URLSearchParams`](#class-urlsearchparams) documentation for details.\n\nUse care when using `.searchParams` to modify the `URL` because,\nper the WHATWG specification, the `URLSearchParams` object uses\ndifferent rules to determine which characters to percent-encode. For\ninstance, the `URL` object will not percent encode the ASCII tilde (`~`)\ncharacter, while `URLSearchParams` will always encode it:\n\n```js\nconst myURL = new URL('https://example.org/abc?foo=~bar');\n\nconsole.log(myURL.search);  // prints ?foo=~bar\n\n// Modify the URL via searchParams...\nmyURL.searchParams.sort();\n\nconsole.log(myURL.search);  // prints ?foo=%7Ebar\n```","summary":"Gets the `URLSearchParams` object representing the query parameters of the URL. This property is read-only but the `URLSearchParams` object it provides can be used to mutate the URL instance; to replace the entirety of query parameters of the URL, use the `url.search` setter. See `URLSearchParams` documentation for details.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/abc?foo=~bar');\n\nconsole.log(myURL.search);  // prints ?foo=~bar\n\n// Modify the URL via searchParams...\nmyURL.searchParams.sort();\n\nconsole.log(myURL.search);  // prints ?foo=%7Ebar"}],"children":[]},{"kind":"property","id":"urlusername","name":"username","title":"`url.username`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"Gets and sets the username portion of the URL.\n\n```js\nconst myURL = new URL('https://abc:xyz@example.com');\nconsole.log(myURL.username);\n// Prints abc\n\nmyURL.username = '123';\nconsole.log(myURL.href);\n// Prints https://123:xyz@example.com/\n```\n\nAny invalid URL characters appearing in the value assigned the `username`\nproperty will be [percent-encoded](#percent-encoding-in-urls). The selection of which\ncharacters to percent-encode may vary somewhat from what the [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost)\nand [`url.format()`](#urlformaturlobject) methods would produce.","summary":"Gets and sets the username portion of the URL.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://abc:xyz@example.com');\nconsole.log(myURL.username);\n// Prints abc\n\nmyURL.username = '123';\nconsole.log(myURL.href);\n// Prints https://123:xyz@example.com/"}],"children":[]},{"kind":"method","id":"urltostring","name":"toString","title":"`url.toString()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"The `toString()` method on the `URL` object returns the serialized URL. The\nvalue returned is equivalent to that of [`url.href`](#urlhref) and [`url.toJSON()`](#urltojson).","summary":"The `toString()` method on the `URL` object returns the serialized URL. The value returned is equivalent to that of `url.href` and `url.toJSON()`.","examples":[],"children":[]},{"kind":"method","id":"urltojson","name":"toJSON","title":"`url.toJSON()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"The `toJSON()` method on the `URL` object returns the serialized URL. The\nvalue returned is equivalent to that of [`url.href`](#urlhref) and\n[`url.toString()`](#urltostring).\n\nThis method is automatically called when an `URL` object is serialized\nwith [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify).\n\n```js\nconst myURLs = [\n  new URL('https://www.example.com'),\n  new URL('https://test.example.org'),\n];\nconsole.log(JSON.stringify(myURLs));\n// Prints [\"https://www.example.com/\",\"https://test.example.org/\"]\n```","summary":"The `toJSON()` method on the `URL` object returns the serialized URL. The value returned is equivalent to that of `url.href` and `url.toString()`.","examples":[{"language":"js","displayName":null,"code":"const myURLs = [\n  new URL('https://www.example.com'),\n  new URL('https://test.example.org'),\n];\nconsole.log(JSON.stringify(myURLs));\n// Prints [\"https://www.example.com/\",\"https://test.example.org/\"]"}],"children":[]},{"kind":"method","id":"urlcreateobjecturlblob","name":"createObjectURL","title":"`URL.createObjectURL(blob)`","scope":"module","overloadOf":null,"stability":null,"added":["v16.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0","v22.17.0"],"prUrl":"https://github.com/nodejs/node/pull/57513","commit":null,"description":"Marking the API stable."}],"signature":{"parameters":[{"name":"blob","type":{"text":"Blob","links":[{"name":"Blob","href":"buffer.html#class-blob","start":0,"end":4}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Creates a `'blob:nodedata:...'` URL string that represents the given {Blob}\nobject and can be used to retrieve the `Blob` later.\n\n```js\nconst {\n  Blob,\n  resolveObjectURL,\n} = require('node:buffer');\n\nconst blob = new Blob(['hello']);\nconst id = URL.createObjectURL(blob);\n\n// later...\n\nconst otherBlob = resolveObjectURL(id);\nconsole.log(otherBlob.size);\n```\n\nThe data stored by the registered {Blob} will be retained in memory until\n`URL.revokeObjectURL()` is called to remove it.\n\n`Blob` objects are registered within the current thread. If using Worker\nThreads, `Blob` objects registered within one Worker will not be available\nto other workers or the main thread.","summary":"Creates a `'blob:nodedata:...'` URL string that represents the given {Blob} object and can be used to retrieve the `Blob` later.","examples":[{"language":"js","displayName":null,"code":"const {\n  Blob,\n  resolveObjectURL,\n} = require('node:buffer');\n\nconst blob = new Blob(['hello']);\nconst id = URL.createObjectURL(blob);\n\n// later...\n\nconst otherBlob = resolveObjectURL(id);\nconsole.log(otherBlob.size);"}],"children":[]},{"kind":"method","id":"urlrevokeobjecturlid","name":"revokeObjectURL","title":"`URL.revokeObjectURL(id)`","scope":"module","overloadOf":null,"stability":null,"added":["v16.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0","v22.17.0"],"prUrl":"https://github.com/nodejs/node/pull/57513","commit":null,"description":"Marking the API stable."}],"signature":{"parameters":[{"name":"id","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A `'blob:nodedata:...` URL string returned by a prior call to\n`URL.createObjectURL()`.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Removes the stored {Blob} identified by the given ID. Attempting to revoke a\nID that isn't registered will silently fail.","summary":"Removes the stored {Blob} identified by the given ID. Attempting to revoke a ID that isn't registered will silently fail.","examples":[],"children":[]},{"kind":"method","id":"urlcanparseinput-base","name":"canParse","title":"`URL.canParse(input[, base])`","scope":"module","overloadOf":null,"stability":null,"added":["v19.9.0","v18.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The absolute or relative input URL to parse. If `input`\nis relative, then `base` is required. If `input` is absolute, the `base`\nis ignored. If `input` is not a string, it is [converted to a string](https://tc39.es/ecma262/#sec-tostring) first.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"base","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The base URL to resolve against if the `input` is not\nabsolute. If `base` is not a string, it is [converted to a string](https://tc39.es/ecma262/#sec-tostring) first.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Checks if an `input` relative to the `base` can be parsed to a `URL`.\n\n```js\nconst isValid = URL.canParse('/foo', 'https://example.org/'); // true\n\nconst isNotValid = URL.canParse('/foo'); // false\n```","summary":"Checks if an `input` relative to the `base` can be parsed to a `URL`.","examples":[{"language":"js","displayName":null,"code":"const isValid = URL.canParse('/foo', 'https://example.org/'); // true\n\nconst isNotValid = URL.canParse('/foo'); // false"}],"children":[]},{"kind":"method","id":"urlparseinput-base","name":"parse","title":"`URL.parse(input[, base])`","scope":"module","overloadOf":null,"stability":null,"added":["v22.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The absolute or relative input URL to parse. If `input`\nis relative, then `base` is required. If `input` is absolute, the `base`\nis ignored. If `input` is not a string, it is [converted to a string](https://tc39.es/ecma262/#sec-tostring) first.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"base","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The base URL to resolve against if the `input` is not\nabsolute. If `base` is not a string, it is [converted to a string](https://tc39.es/ecma262/#sec-tostring) first.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"URL | null","links":[{"name":"URL","href":"url.html#the-whatwg-url-api","start":0,"end":3},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":6,"end":10}]},"description":""}},"description":"Parses a string as a URL. If `base` is provided, it will be used as the base\nURL for the purpose of resolving non-absolute `input` URLs. Returns `null`\nif the parameters can't be resolved to a valid URL.","summary":"Parses a string as a URL. If `base` is provided, it will be used as the base URL for the purpose of resolving non-absolute `input` URLs. Returns `null` if the parameters can't be resolved to a valid URL.","examples":[],"children":[]}]},{"kind":"class","id":"class-urlpattern","name":"URLPattern","title":"Class: `URLPattern`","scope":"module","overloadOf":null,"stability":{"index":"1","description":"Experimental"},"added":["v23.8.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"The `URLPattern` API provides an interface to match URLs or parts of URLs\nagainst a pattern.\n\n```js\nconst myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');\nconsole.log(myPattern.exec('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints:\n// {\n//  \"hash\": { \"groups\": {  \"0\": \"\" },  \"input\": \"\" },\n//  \"hostname\": { \"groups\": {}, \"input\": \"nodejs.org\" },\n//  \"inputs\": [\n//    \"https://nodejs.org/docs/latest/api/dns.html\"\n//  ],\n//  \"password\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"pathname\": { \"groups\": { \"0\": \"dns\" }, \"input\": \"/docs/latest/api/dns.html\" },\n//  \"port\": { \"groups\": {}, \"input\": \"\" },\n//  \"protocol\": { \"groups\": {}, \"input\": \"https\" },\n//  \"search\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"username\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" }\n// }\n\nconsole.log(myPattern.test('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints: true\n```","summary":"The `URLPattern` API provides an interface to match URLs or parts of URLs against a pattern.","examples":[{"language":"js","displayName":null,"code":"const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');\nconsole.log(myPattern.exec('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints:\n// {\n//  \"hash\": { \"groups\": {  \"0\": \"\" },  \"input\": \"\" },\n//  \"hostname\": { \"groups\": {}, \"input\": \"nodejs.org\" },\n//  \"inputs\": [\n//    \"https://nodejs.org/docs/latest/api/dns.html\"\n//  ],\n//  \"password\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"pathname\": { \"groups\": { \"0\": \"dns\" }, \"input\": \"/docs/latest/api/dns.html\" },\n//  \"port\": { \"groups\": {}, \"input\": \"\" },\n//  \"protocol\": { \"groups\": {}, \"input\": \"https\" },\n//  \"search\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"username\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" }\n// }\n\nconsole.log(myPattern.test('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints: true"}],"children":[{"kind":"constructor","id":"new-urlpattern","name":"URLPattern","title":"`new URLPattern()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Instantiate a new empty `URLPattern` object.","summary":"Instantiate a new empty `URLPattern` object.","examples":[],"children":[]},{"kind":"constructor","id":"new-urlpatternstring-baseurl-options","name":"URLPattern","title":"`new URLPattern(string[, baseURL][, options])`","scope":"module","overloadOf":"new-urlpattern","stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"string","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A URL string","default":null,"optional":false,"rest":false,"properties":[]},{"name":"baseURL","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"A base URL string","default":null,"optional":true,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Options","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Parse the `string` as a URL, and use it to instantiate a new\n`URLPattern` object.\n\nIf `baseURL` is not specified, it defaults to `undefined`.\n\nAn option can have `ignoreCase` boolean attribute which enables\ncase-insensitive matching if set to true.\n\nThe constructor can throw a `TypeError` to indicate parsing failure.","summary":"Parse the `string` as a URL, and use it to instantiate a new `URLPattern` object.","examples":[],"children":[]},{"kind":"constructor","id":"new-urlpatternobj-baseurl-options","name":"URLPattern","title":"`new URLPattern(obj[, baseURL][, options])`","scope":"module","overloadOf":"new-urlpattern","stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"obj","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"An input pattern","default":null,"optional":false,"rest":false,"properties":[]},{"name":"baseURL","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"A base URL string","default":null,"optional":true,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Options","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Parse the `Object` as an input pattern, and use it to instantiate a new\n`URLPattern` object. The object members can be any of `protocol`, `username`,\n`password`, `hostname`, `port`, `pathname`, `search`, `hash` or `baseURL`.\n\nIf `baseURL` is not specified, it defaults to `undefined`.\n\nAn option can have `ignoreCase` boolean attribute which enables\ncase-insensitive matching if set to true.\n\nThe constructor can throw a `TypeError` to indicate parsing failure.","summary":"Parse the `Object` as an input pattern, and use it to instantiate a new `URLPattern` object. The object members can be any of `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search`, `hash` or `baseURL`.","examples":[],"children":[]},{"kind":"method","id":"urlpatternexecinput-baseurl","name":"exec","title":"`urlPattern.exec(input[, baseURL])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string | Object","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":9,"end":15}]},"description":"A URL or URL parts","default":null,"optional":false,"rest":false,"properties":[]},{"name":"baseURL","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"A base URL string","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Input can be a string or an object providing the individual URL parts. The\nobject members can be any of `protocol`, `username`, `password`, `hostname`,\n`port`, `pathname`, `search`, `hash` or `baseURL`.\n\nIf `baseURL` is not specified, it will default to `undefined`.\n\nReturns an object with an `inputs` key containing the array of arguments\npassed into the function and keys of the URL components which contains the\nmatched input and matched groups.\n\n```js\nconst myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');\nconsole.log(myPattern.exec('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints:\n// {\n//  \"hash\": { \"groups\": {  \"0\": \"\" },  \"input\": \"\" },\n//  \"hostname\": { \"groups\": {}, \"input\": \"nodejs.org\" },\n//  \"inputs\": [\n//    \"https://nodejs.org/docs/latest/api/dns.html\"\n//  ],\n//  \"password\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"pathname\": { \"groups\": { \"0\": \"dns\" }, \"input\": \"/docs/latest/api/dns.html\" },\n//  \"port\": { \"groups\": {}, \"input\": \"\" },\n//  \"protocol\": { \"groups\": {}, \"input\": \"https\" },\n//  \"search\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"username\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" }\n// }\n```","summary":"Input can be a string or an object providing the individual URL parts. The object members can be any of `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search`, `hash` or `baseURL`.","examples":[{"language":"js","displayName":null,"code":"const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');\nconsole.log(myPattern.exec('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints:\n// {\n//  \"hash\": { \"groups\": {  \"0\": \"\" },  \"input\": \"\" },\n//  \"hostname\": { \"groups\": {}, \"input\": \"nodejs.org\" },\n//  \"inputs\": [\n//    \"https://nodejs.org/docs/latest/api/dns.html\"\n//  ],\n//  \"password\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"pathname\": { \"groups\": { \"0\": \"dns\" }, \"input\": \"/docs/latest/api/dns.html\" },\n//  \"port\": { \"groups\": {}, \"input\": \"\" },\n//  \"protocol\": { \"groups\": {}, \"input\": \"https\" },\n//  \"search\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" },\n//  \"username\": { \"groups\": { \"0\": \"\" }, \"input\": \"\" }\n// }"}],"children":[]},{"kind":"method","id":"urlpatterntestinput-baseurl","name":"test","title":"`urlPattern.test(input[, baseURL])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"input","type":{"text":"string | Object","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":9,"end":15}]},"description":"A URL or URL parts","default":null,"optional":false,"rest":false,"properties":[]},{"name":"baseURL","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"A base URL string","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Input can be a string or an object providing the individual URL parts. The\nobject members can be any of `protocol`, `username`, `password`, `hostname`,\n`port`, `pathname`, `search`, `hash` or `baseURL`.\n\nIf `baseURL` is not specified, it will default to `undefined`.\n\nReturns a boolean indicating if the input matches the current pattern.\n\n```js\nconst myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');\nconsole.log(myPattern.test('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints: true\n```","summary":"Input can be a string or an object providing the individual URL parts. The object members can be any of `protocol`, `username`, `password`, `hostname`, `port`, `pathname`, `search`, `hash` or `baseURL`.","examples":[{"language":"js","displayName":null,"code":"const myPattern = new URLPattern('https://nodejs.org/docs/latest/api/*.html');\nconsole.log(myPattern.test('https://nodejs.org/docs/latest/api/dns.html'));\n// Prints: true"}],"children":[]}]},{"kind":"class","id":"class-urlsearchparams","name":"URLSearchParams","title":"Class: `URLSearchParams`","scope":"module","overloadOf":null,"stability":null,"added":["v7.5.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/18281","commit":null,"description":"The class is now available on the global object."}],"extends":null,"description":"The `URLSearchParams` API provides read and write access to the query of a\n`URL`. The `URLSearchParams` class can also be used standalone with one of the\nfour following constructors.\nThe `URLSearchParams` class is also available on the global object.\n\nThe WHATWG `URLSearchParams` interface and the [`querystring`](querystring.html) module have\nsimilar purpose, but the purpose of the [`querystring`](querystring.html) module is more\ngeneral, as it allows the customization of delimiter characters (`&` and `=`).\nOn the other hand, this API is designed purely for URL query strings.\n\n```js\nconst myURL = new URL('https://example.org/?abc=123');\nconsole.log(myURL.searchParams.get('abc'));\n// Prints 123\n\nmyURL.searchParams.append('abc', 'xyz');\nconsole.log(myURL.href);\n// Prints https://example.org/?abc=123&abc=xyz\n\nmyURL.searchParams.delete('abc');\nmyURL.searchParams.set('a', 'b');\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b\n\nconst newSearchParams = new URLSearchParams(myURL.searchParams);\n// The above is equivalent to\n// const newSearchParams = new URLSearchParams(myURL.search);\n\nnewSearchParams.append('a', 'c');\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b\nconsole.log(newSearchParams.toString());\n// Prints a=b&a=c\n\n// newSearchParams.toString() is implicitly called\nmyURL.search = newSearchParams;\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b&a=c\nnewSearchParams.delete('a');\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b&a=c\n```","summary":"The `URLSearchParams` API provides read and write access to the query of a `URL`. The `URLSearchParams` class can also be used standalone with one of the four following constructors. The `URLSearchParams` class is also available on the global object.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/?abc=123');\nconsole.log(myURL.searchParams.get('abc'));\n// Prints 123\n\nmyURL.searchParams.append('abc', 'xyz');\nconsole.log(myURL.href);\n// Prints https://example.org/?abc=123&abc=xyz\n\nmyURL.searchParams.delete('abc');\nmyURL.searchParams.set('a', 'b');\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b\n\nconst newSearchParams = new URLSearchParams(myURL.searchParams);\n// The above is equivalent to\n// const newSearchParams = new URLSearchParams(myURL.search);\n\nnewSearchParams.append('a', 'c');\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b\nconsole.log(newSearchParams.toString());\n// Prints a=b&a=c\n\n// newSearchParams.toString() is implicitly called\nmyURL.search = newSearchParams;\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b&a=c\nnewSearchParams.delete('a');\nconsole.log(myURL.href);\n// Prints https://example.org/?a=b&a=c"}],"children":[{"kind":"constructor","id":"new-urlsearchparams","name":"URLSearchParams","title":"`new URLSearchParams()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Instantiate a new empty `URLSearchParams` object.","summary":"Instantiate a new empty `URLSearchParams` object.","examples":[],"children":[]},{"kind":"constructor","id":"new-urlsearchparamsstring","name":"URLSearchParams","title":"`new URLSearchParams(string)`","scope":"module","overloadOf":"new-urlsearchparams","stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"string","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A query string","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Parse the `string` as a query string, and use it to instantiate a new\n`URLSearchParams` object. A leading `'?'`, if present, is ignored.\n\n```js\nlet params;\n\nparams = new URLSearchParams('user=abc&query=xyz');\nconsole.log(params.get('user'));\n// Prints 'abc'\nconsole.log(params.toString());\n// Prints 'user=abc&query=xyz'\n\nparams = new URLSearchParams('?user=abc&query=xyz');\nconsole.log(params.toString());\n// Prints 'user=abc&query=xyz'\n```","summary":"Parse the `string` as a query string, and use it to instantiate a new `URLSearchParams` object. A leading `'?'`, if present, is ignored.","examples":[{"language":"js","displayName":null,"code":"let params;\n\nparams = new URLSearchParams('user=abc&query=xyz');\nconsole.log(params.get('user'));\n// Prints 'abc'\nconsole.log(params.toString());\n// Prints 'user=abc&query=xyz'\n\nparams = new URLSearchParams('?user=abc&query=xyz');\nconsole.log(params.toString());\n// Prints 'user=abc&query=xyz'"}],"children":[]},{"kind":"constructor","id":"new-urlsearchparamsobj","name":"URLSearchParams","title":"`new URLSearchParams(obj)`","scope":"module","overloadOf":"new-urlsearchparams","stability":null,"added":["v7.10.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"obj","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"An object representing a collection of key-value pairs","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Instantiate a new `URLSearchParams` object with a query hash map. The key and\nvalue of each property of `obj` are always coerced to strings.\n\nUnlike [`querystring`](querystring.html) module, duplicate keys in the form of array values are\nnot allowed. Arrays are stringified using [`array.toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString), which simply\njoins all array elements with commas.\n\n```js\nconst params = new URLSearchParams({\n  user: 'abc',\n  query: ['first', 'second'],\n});\nconsole.log(params.getAll('query'));\n// Prints [ 'first,second' ]\nconsole.log(params.toString());\n// Prints 'user=abc&query=first%2Csecond'\n```","summary":"Instantiate a new `URLSearchParams` object with a query hash map. The key and value of each property of `obj` are always coerced to strings.","examples":[{"language":"js","displayName":null,"code":"const params = new URLSearchParams({\n  user: 'abc',\n  query: ['first', 'second'],\n});\nconsole.log(params.getAll('query'));\n// Prints [ 'first,second' ]\nconsole.log(params.toString());\n// Prints 'user=abc&query=first%2Csecond'"}],"children":[]},{"kind":"constructor","id":"new-urlsearchparamsiterable","name":"URLSearchParams","title":"`new URLSearchParams(iterable)`","scope":"module","overloadOf":"new-urlsearchparams","stability":null,"added":["v7.10.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"iterable","type":{"text":"Iterable","links":[{"name":"Iterable","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols#the_iterable_protocol","start":0,"end":8}]},"description":"An iterable object whose elements are key-value pairs","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Instantiate a new `URLSearchParams` object with an iterable map in a way that\nis similar to {Map}'s constructor. `iterable` can be an `Array` or any\niterable object. That means `iterable` can be another `URLSearchParams`, in\nwhich case the constructor will simply create a clone of the provided\n`URLSearchParams`. Elements of `iterable` are key-value pairs, and can\nthemselves be any iterable object.\n\nDuplicate keys are allowed.\n\n```js\nlet params;\n\n// Using an array\nparams = new URLSearchParams([\n  ['user', 'abc'],\n  ['query', 'first'],\n  ['query', 'second'],\n]);\nconsole.log(params.toString());\n// Prints 'user=abc&query=first&query=second'\n\n// Using a Map object\nconst map = new Map();\nmap.set('user', 'abc');\nmap.set('query', 'xyz');\nparams = new URLSearchParams(map);\nconsole.log(params.toString());\n// Prints 'user=abc&query=xyz'\n\n// Using a generator function\nfunction* getQueryPairs() {\n  yield ['user', 'abc'];\n  yield ['query', 'first'];\n  yield ['query', 'second'];\n}\nparams = new URLSearchParams(getQueryPairs());\nconsole.log(params.toString());\n// Prints 'user=abc&query=first&query=second'\n\n// Each key-value pair must have exactly two elements\nnew URLSearchParams([\n  ['user', 'abc', 'error'],\n]);\n// Throws TypeError [ERR_INVALID_TUPLE]:\n//        Each query pair must be an iterable [name, value] tuple\n```","summary":"Instantiate a new `URLSearchParams` object with an iterable map in a way that is similar to {Map}'s constructor. `iterable` can be an `Array` or any iterable object. That means `iterable` can be another `URLSearchParams`, in which case the constructor will simply create a clone of the provided `URLSearchParams`. Elements of `iterable` are key-value pairs, and can themselves be any iterable object.","examples":[{"language":"js","displayName":null,"code":"let params;\n\n// Using an array\nparams = new URLSearchParams([\n  ['user', 'abc'],\n  ['query', 'first'],\n  ['query', 'second'],\n]);\nconsole.log(params.toString());\n// Prints 'user=abc&query=first&query=second'\n\n// Using a Map object\nconst map = new Map();\nmap.set('user', 'abc');\nmap.set('query', 'xyz');\nparams = new URLSearchParams(map);\nconsole.log(params.toString());\n// Prints 'user=abc&query=xyz'\n\n// Using a generator function\nfunction* getQueryPairs() {\n  yield ['user', 'abc'];\n  yield ['query', 'first'];\n  yield ['query', 'second'];\n}\nparams = new URLSearchParams(getQueryPairs());\nconsole.log(params.toString());\n// Prints 'user=abc&query=first&query=second'\n\n// Each key-value pair must have exactly two elements\nnew URLSearchParams([\n  ['user', 'abc', 'error'],\n]);\n// Throws TypeError [ERR_INVALID_TUPLE]:\n//        Each query pair must be an iterable [name, value] tuple"}],"children":[]},{"kind":"method","id":"urlsearchparamsappendname-value","name":"append","title":"`urlSearchParams.append(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Append a new name-value pair to the query string.","summary":"Append a new name-value pair to the query string.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamsdeletename-value","name":"delete","title":"`urlSearchParams.delete(name[, value])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.2.0","v18.18.0"],"prUrl":"https://github.com/nodejs/node/pull/47885","commit":null,"description":"Add support for optional `value` argument."}],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"If `value` is provided, removes all name-value pairs\nwhere name is `name` and value is `value`..\n\nIf `value` is not provided, removes all name-value pairs whose name is `name`.","summary":"If `value` is provided, removes all name-value pairs where name is `name` and value is `value`..","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamsentries","name":"entries","title":"`urlSearchParams.entries()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Iterator","links":[{"name":"Iterator","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Iterator","start":0,"end":8}]},"description":""}},"description":"Returns an ES6 `Iterator` over each of the name-value pairs in the query.\nEach item of the iterator is a JavaScript `Array`. The first item of the `Array`\nis the `name`, the second item of the `Array` is the `value`.\n\nAlias for [`urlSearchParams[Symbol.iterator]()`](#urlsearchparamssymboliterator).","summary":"Returns an ES6 `Iterator` over each of the name-value pairs in the query. Each item of the iterator is a JavaScript `Array`. The first item of the `Array` is the `name`, the second item of the `Array` is the `value`.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamsforeachfn-thisarg","name":"forEach","title":"`urlSearchParams.forEach(fn[, thisArg])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41678","commit":null,"description":"Passing an invalid callback to the `fn` argument now throws `ERR_INVALID_ARG_TYPE` instead of `ERR_INVALID_CALLBACK`."}],"signature":{"parameters":[{"name":"fn","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Invoked for each name-value pair in the query","default":null,"optional":false,"rest":false,"properties":[]},{"name":"thisArg","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"To be used as `this` value for when `fn` is called","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Iterates over each name-value pair in the query and invokes the given function.\n\n```js\nconst myURL = new URL('https://example.org/?a=b&c=d');\nmyURL.searchParams.forEach((value, name, searchParams) => {\n  console.log(name, value, myURL.searchParams === searchParams);\n});\n// Prints:\n//   a b true\n//   c d true\n```","summary":"Iterates over each name-value pair in the query and invokes the given function.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://example.org/?a=b&c=d');\nmyURL.searchParams.forEach((value, name, searchParams) => {\n  console.log(name, value, myURL.searchParams === searchParams);\n});\n// Prints:\n//   a b true\n//   c d true"}],"children":[]},{"kind":"method","id":"urlsearchparamsgetname","name":"get","title":"`urlSearchParams.get(name)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string | null","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":9,"end":13}]},"description":"A string or `null` if there is no name-value pair\nwith the given `name`."}},"description":"Returns the value of the first name-value pair whose name is `name`. If there\nare no such pairs, `null` is returned.","summary":"Returns the value of the first name-value pair whose name is `name`. If there are no such pairs, `null` is returned.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamsgetallname","name":"getAll","title":"`urlSearchParams.getAll(name)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns the values of all name-value pairs whose name is `name`. If there are\nno such pairs, an empty array is returned.","summary":"Returns the values of all name-value pairs whose name is `name`. If there are no such pairs, an empty array is returned.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamshasname-value","name":"has","title":"`urlSearchParams.has(name[, value])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.2.0","v18.18.0"],"prUrl":"https://github.com/nodejs/node/pull/47885","commit":null,"description":"Add support for optional `value` argument."}],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Checks if the `URLSearchParams` object contains key-value pair(s) based on\n`name` and an optional `value` argument.\n\nIf `value` is provided, returns `true` when name-value pair with\nsame `name` and `value` exists.\n\nIf `value` is not provided, returns `true` if there is at least one name-value\npair whose name is `name`.","summary":"Checks if the `URLSearchParams` object contains key-value pair(s) based on `name` and an optional `value` argument.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamskeys","name":"keys","title":"`urlSearchParams.keys()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Iterator","links":[{"name":"Iterator","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Iterator","start":0,"end":8}]},"description":""}},"description":"Returns an ES6 `Iterator` over the names of each name-value pair.\n\n```js\nconst params = new URLSearchParams('foo=bar&foo=baz');\nfor (const name of params.keys()) {\n  console.log(name);\n}\n// Prints:\n//   foo\n//   foo\n```","summary":"Returns an ES6 `Iterator` over the names of each name-value pair.","examples":[{"language":"js","displayName":null,"code":"const params = new URLSearchParams('foo=bar&foo=baz');\nfor (const name of params.keys()) {\n  console.log(name);\n}\n// Prints:\n//   foo\n//   foo"}],"children":[]},{"kind":"method","id":"urlsearchparamssetname-value","name":"set","title":"`urlSearchParams.set(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Sets the value in the `URLSearchParams` object associated with `name` to\n`value`. If there are any pre-existing name-value pairs whose names are `name`,\nset the first such pair's value to `value` and remove all others. If not,\nappend the name-value pair to the query string.\n\n```js\nconst params = new URLSearchParams();\nparams.append('foo', 'bar');\nparams.append('foo', 'baz');\nparams.append('abc', 'def');\nconsole.log(params.toString());\n// Prints foo=bar&foo=baz&abc=def\n\nparams.set('foo', 'def');\nparams.set('xyz', 'opq');\nconsole.log(params.toString());\n// Prints foo=def&abc=def&xyz=opq\n```","summary":"Sets the value in the `URLSearchParams` object associated with `name` to `value`. If there are any pre-existing name-value pairs whose names are `name`, set the first such pair's value to `value` and remove all others. If not, append the name-value pair to the query string.","examples":[{"language":"js","displayName":null,"code":"const params = new URLSearchParams();\nparams.append('foo', 'bar');\nparams.append('foo', 'baz');\nparams.append('abc', 'def');\nconsole.log(params.toString());\n// Prints foo=bar&foo=baz&abc=def\n\nparams.set('foo', 'def');\nparams.set('xyz', 'opq');\nconsole.log(params.toString());\n// Prints foo=def&abc=def&xyz=opq"}],"children":[]},{"kind":"property","id":"urlsearchparamssize","name":"size","title":"`urlSearchParams.size`","scope":"module","overloadOf":null,"stability":null,"added":["v19.8.0","v18.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The total number of parameter entries.","summary":"The total number of parameter entries.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamssort","name":"sort","title":"`urlSearchParams.sort()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Sort all existing name-value pairs in-place by their names. Sorting is done\nwith a [stable sorting algorithm](https://en.wikipedia.org/wiki/Sorting_algorithm#Stability), so relative order between name-value pairs\nwith the same name is preserved.\n\nThis method can be used, in particular, to increase cache hits.\n\n```js\nconst params = new URLSearchParams('query[]=abc&type=search&query[]=123');\nparams.sort();\nconsole.log(params.toString());\n// Prints query%5B%5D=abc&query%5B%5D=123&type=search\n```","summary":"Sort all existing name-value pairs in-place by their names. Sorting is done with a stable sorting algorithm, so relative order between name-value pairs with the same name is preserved.","examples":[{"language":"js","displayName":null,"code":"const params = new URLSearchParams('query[]=abc&type=search&query[]=123');\nparams.sort();\nconsole.log(params.toString());\n// Prints query%5B%5D=abc&query%5B%5D=123&type=search"}],"children":[]},{"kind":"method","id":"urlsearchparamstostring","name":"toString","title":"`urlSearchParams.toString()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns the search parameters serialized as a string, with characters\npercent-encoded where necessary.","summary":"Returns the search parameters serialized as a string, with characters percent-encoded where necessary.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamsvalues","name":"values","title":"`urlSearchParams.values()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Iterator","links":[{"name":"Iterator","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Iterator","start":0,"end":8}]},"description":""}},"description":"Returns an ES6 `Iterator` over the values of each name-value pair.","summary":"Returns an ES6 `Iterator` over the values of each name-value pair.","examples":[],"children":[]},{"kind":"method","id":"urlsearchparamssymboliterator","name":"[Symbol.iterator]","title":"`urlSearchParams[Symbol.iterator]()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Iterator","links":[{"name":"Iterator","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Iterator","start":0,"end":8}]},"description":""}},"description":"Returns an ES6 `Iterator` over each of the name-value pairs in the query string.\nEach item of the iterator is a JavaScript `Array`. The first item of the `Array`\nis the `name`, the second item of the `Array` is the `value`.\n\nAlias for [`urlSearchParams.entries()`](#urlsearchparamsentries).\n\n```js\nconst params = new URLSearchParams('foo=bar&xyz=baz');\nfor (const [name, value] of params) {\n  console.log(name, value);\n}\n// Prints:\n//   foo bar\n//   xyz baz\n```","summary":"Returns an ES6 `Iterator` over each of the name-value pairs in the query string. Each item of the iterator is a JavaScript `Array`. The first item of the `Array` is the `name`, the second item of the `Array` is the `value`.","examples":[{"language":"js","displayName":null,"code":"const params = new URLSearchParams('foo=bar&xyz=baz');\nfor (const [name, value] of params) {\n  console.log(name, value);\n}\n// Prints:\n//   foo bar\n//   xyz baz"}],"children":[]}]},{"kind":"method","id":"urldomaintoasciidomain","name":"domainToASCII","title":"`url.domainToASCII(domain)`","scope":"module","overloadOf":null,"stability":null,"added":["v7.4.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.0.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/47339","commit":null,"description":"ICU requirement is removed."}],"signature":{"parameters":[{"name":"domain","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) ASCII serialization of the `domain`. If `domain` is an\ninvalid domain, the empty string is returned.\n\nIt performs the inverse operation to [`url.domainToUnicode()`](#urldomaintounicodedomain).\n\n```mjs\nimport url from 'node:url';\n\nconsole.log(url.domainToASCII('español.com'));\n// Prints xn--espaol-zwa.com\nconsole.log(url.domainToASCII('中文.com'));\n// Prints xn--fiq228c.com\nconsole.log(url.domainToASCII('xn--iñvalid.com'));\n// Prints an empty string\n```\n\n```cjs\nconst url = require('node:url');\n\nconsole.log(url.domainToASCII('español.com'));\n// Prints xn--espaol-zwa.com\nconsole.log(url.domainToASCII('中文.com'));\n// Prints xn--fiq228c.com\nconsole.log(url.domainToASCII('xn--iñvalid.com'));\n// Prints an empty string\n```","summary":"Returns the Punycode ASCII serialization of the `domain`. If `domain` is an invalid domain, the empty string is returned.","examples":[{"language":"mjs","displayName":null,"code":"import url from 'node:url';\n\nconsole.log(url.domainToASCII('español.com'));\n// Prints xn--espaol-zwa.com\nconsole.log(url.domainToASCII('中文.com'));\n// Prints xn--fiq228c.com\nconsole.log(url.domainToASCII('xn--iñvalid.com'));\n// Prints an empty string"},{"language":"cjs","displayName":null,"code":"const url = require('node:url');\n\nconsole.log(url.domainToASCII('español.com'));\n// Prints xn--espaol-zwa.com\nconsole.log(url.domainToASCII('中文.com'));\n// Prints xn--fiq228c.com\nconsole.log(url.domainToASCII('xn--iñvalid.com'));\n// Prints an empty string"}],"children":[]},{"kind":"method","id":"urldomaintounicodedomain","name":"domainToUnicode","title":"`url.domainToUnicode(domain)`","scope":"module","overloadOf":null,"stability":null,"added":["v7.4.0","v6.13.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v20.0.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/47339","commit":null,"description":"ICU requirement is removed."}],"signature":{"parameters":[{"name":"domain","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns the Unicode serialization of the `domain`. If `domain` is an invalid\ndomain, the empty string is returned.\n\nIt performs the inverse operation to [`url.domainToASCII()`](#urldomaintoasciidomain).\n\n```mjs\nimport url from 'node:url';\n\nconsole.log(url.domainToUnicode('xn--espaol-zwa.com'));\n// Prints español.com\nconsole.log(url.domainToUnicode('xn--fiq228c.com'));\n// Prints 中文.com\nconsole.log(url.domainToUnicode('xn--iñvalid.com'));\n// Prints an empty string\n```\n\n```cjs\nconst url = require('node:url');\n\nconsole.log(url.domainToUnicode('xn--espaol-zwa.com'));\n// Prints español.com\nconsole.log(url.domainToUnicode('xn--fiq228c.com'));\n// Prints 中文.com\nconsole.log(url.domainToUnicode('xn--iñvalid.com'));\n// Prints an empty string\n```","summary":"Returns the Unicode serialization of the `domain`. If `domain` is an invalid domain, the empty string is returned.","examples":[{"language":"mjs","displayName":null,"code":"import url from 'node:url';\n\nconsole.log(url.domainToUnicode('xn--espaol-zwa.com'));\n// Prints español.com\nconsole.log(url.domainToUnicode('xn--fiq228c.com'));\n// Prints 中文.com\nconsole.log(url.domainToUnicode('xn--iñvalid.com'));\n// Prints an empty string"},{"language":"cjs","displayName":null,"code":"const url = require('node:url');\n\nconsole.log(url.domainToUnicode('xn--espaol-zwa.com'));\n// Prints español.com\nconsole.log(url.domainToUnicode('xn--fiq228c.com'));\n// Prints 中文.com\nconsole.log(url.domainToUnicode('xn--iñvalid.com'));\n// Prints an empty string"}],"children":[]},{"kind":"method","id":"urlfileurltopathurl-options","name":"fileURLToPath","title":"`url.fileURLToPath(url[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v10.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v22.1.0","v20.13.0"],"prUrl":"https://github.com/nodejs/node/pull/52509","commit":null,"description":"The `options` argument can now be used to determine how to parse the `path` argument."}],"signature":{"parameters":[{"name":"url","type":{"text":"URL | string","links":[{"name":"URL","href":"url.html#the-whatwg-url-api","start":0,"end":3},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":6,"end":12}]},"description":"The file URL string or URL object to convert to a path.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"windows","type":{"text":"boolean | undefined","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":10,"end":19}]},"description":"`true` if the `path` should be\nreturn as a windows filepath, `false` for posix, and\n`undefined` for the system default.","default":"undefined","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The fully-resolved platform-specific Node.js file path."}},"description":"This function ensures the correct decodings of percent-encoded characters as\nwell as ensuring a cross-platform valid absolute path string.\n\n**Security Considerations:**\n\nThis function decodes percent-encoded characters, including encoded dot-segments\n(`%2e` as `.` and `%2e%2e` as `..`), and then normalizes the resulting path.\nThis means that encoded directory traversal sequences (such as `%2e%2e`) are\ndecoded and processed as actual path traversal, even though encoded slashes\n(`%2F`, `%5C`) are correctly rejected.\n\n**Applications must not rely on `fileURLToPath()` alone to prevent directory\ntraversal attacks.** Always perform explicit path validation and security checks\non the returned path value to ensure it remains within expected boundaries\nbefore using it for file system operations.\n\n```mjs\nimport { fileURLToPath } from 'node:url';\n\nconst __filename = fileURLToPath(import.meta.url);\n\nnew URL('file:///C:/path/').pathname;      // Incorrect: /C:/path/\nfileURLToPath('file:///C:/path/');         // Correct:   C:\\path\\ (Windows)\n\nnew URL('file://nas/foo.txt').pathname;    // Incorrect: /foo.txt\nfileURLToPath('file://nas/foo.txt');       // Correct:   \\\\nas\\foo.txt (Windows)\n\nnew URL('file:///你好.txt').pathname;      // Incorrect: /%E4%BD%A0%E5%A5%BD.txt\nfileURLToPath('file:///你好.txt');         // Correct:   /你好.txt (POSIX)\n\nnew URL('file:///hello world').pathname;   // Incorrect: /hello%20world\nfileURLToPath('file:///hello world');      // Correct:   /hello world (POSIX)\n```\n\n```cjs\nconst { fileURLToPath } = require('node:url');\nnew URL('file:///C:/path/').pathname;      // Incorrect: /C:/path/\nfileURLToPath('file:///C:/path/');         // Correct:   C:\\path\\ (Windows)\n\nnew URL('file://nas/foo.txt').pathname;    // Incorrect: /foo.txt\nfileURLToPath('file://nas/foo.txt');       // Correct:   \\\\nas\\foo.txt (Windows)\n\nnew URL('file:///你好.txt').pathname;      // Incorrect: /%E4%BD%A0%E5%A5%BD.txt\nfileURLToPath('file:///你好.txt');         // Correct:   /你好.txt (POSIX)\n\nnew URL('file:///hello world').pathname;   // Incorrect: /hello%20world\nfileURLToPath('file:///hello world');      // Correct:   /hello world (POSIX)\n```","summary":"This function ensures the correct decodings of percent-encoded characters as well as ensuring a cross-platform valid absolute path string.","examples":[{"language":"mjs","displayName":null,"code":"import { fileURLToPath } from 'node:url';\n\nconst __filename = fileURLToPath(import.meta.url);\n\nnew URL('file:///C:/path/').pathname;      // Incorrect: /C:/path/\nfileURLToPath('file:///C:/path/');         // Correct:   C:\\path\\ (Windows)\n\nnew URL('file://nas/foo.txt').pathname;    // Incorrect: /foo.txt\nfileURLToPath('file://nas/foo.txt');       // Correct:   \\\\nas\\foo.txt (Windows)\n\nnew URL('file:///你好.txt').pathname;      // Incorrect: /%E4%BD%A0%E5%A5%BD.txt\nfileURLToPath('file:///你好.txt');         // Correct:   /你好.txt (POSIX)\n\nnew URL('file:///hello world').pathname;   // Incorrect: /hello%20world\nfileURLToPath('file:///hello world');      // Correct:   /hello world (POSIX)"},{"language":"cjs","displayName":null,"code":"const { fileURLToPath } = require('node:url');\nnew URL('file:///C:/path/').pathname;      // Incorrect: /C:/path/\nfileURLToPath('file:///C:/path/');         // Correct:   C:\\path\\ (Windows)\n\nnew URL('file://nas/foo.txt').pathname;    // Incorrect: /foo.txt\nfileURLToPath('file://nas/foo.txt');       // Correct:   \\\\nas\\foo.txt (Windows)\n\nnew URL('file:///你好.txt').pathname;      // Incorrect: /%E4%BD%A0%E5%A5%BD.txt\nfileURLToPath('file:///你好.txt');         // Correct:   /你好.txt (POSIX)\n\nnew URL('file:///hello world').pathname;   // Incorrect: /hello%20world\nfileURLToPath('file:///hello world');      // Correct:   /hello world (POSIX)"}],"children":[]},{"kind":"method","id":"urlfileurltopathbufferurl-options","name":"fileURLToPathBuffer","title":"`url.fileURLToPathBuffer(url[, options])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"url","type":{"text":"URL | string","links":[{"name":"URL","href":"url.html#the-whatwg-url-api","start":0,"end":3},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":6,"end":12}]},"description":"The file URL string or URL object to convert to a path.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"windows","type":{"text":"boolean | undefined","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":10,"end":19}]},"description":"`true` if the `path` should be\nreturn as a windows filepath, `false` for posix, and\n`undefined` for the system default.","default":"undefined","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The fully-resolved platform-specific Node.js file path\nas a {Buffer}."}},"description":"<!--\nadded:\n - v24.3.0\n - v22.18.0\n-->\n\nLike `url.fileURLToPath(...)` except that instead of returning a string\nrepresentation of the path, a `Buffer` is returned. This conversion is\nhelpful when the input URL contains percent-encoded segments that are\nnot valid UTF-8 / Unicode sequences.\n\n**Security Considerations:**\n\nThis function has the same security considerations as [`url.fileURLToPath()`](#urlfileurltopathurl-options).\nIt decodes percent-encoded characters, including encoded dot-segments\n(`%2e` as `.` and `%2e%2e` as `..`), and normalizes the path. **Applications\nmust not rely on this function alone to prevent directory traversal attacks.**\nAlways perform explicit path validation on the returned buffer value before\nusing it for file system operations.","summary":"Like `url.fileURLToPath(...)` except that instead of returning a string representation of the path, a `Buffer` is returned. This conversion is helpful when the input URL contains percent-encoded segments that are not valid UTF-8 / Unicode sequences.","examples":[],"children":[]},{"kind":"method","id":"urlformaturl-options","name":"format","title":"`url.format(URL[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v7.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"URL","type":{"text":"URL","links":[{"name":"URL","href":"url.html#the-whatwg-url-api","start":0,"end":3}]},"description":"A [WHATWG URL](#the-whatwg-url-api) object","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"auth","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the serialized URL string should include the\nusername and password, `false` otherwise.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"fragment","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the serialized URL string should include the\nfragment, `false` otherwise.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"search","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if the serialized URL string should include the\nsearch query, `false` otherwise.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"unicode","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"`true` if Unicode characters appearing in the host\ncomponent of the URL string should be encoded directly as opposed to being\nPunycode encoded.","default":"false","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns a customizable serialization of a URL `String` representation of a\n[WHATWG URL](#the-whatwg-url-api) object.\n\nThe URL object has both a `toString()` method and `href` property that return\nstring serializations of the URL. These are not, however, customizable in\nany way. The `url.format(URL[, options])` method allows for basic customization\nof the output.\n\n```mjs\nimport url from 'node:url';\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(myURL.href);\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(myURL.toString());\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));\n// Prints 'https://測試/?abc'\n```\n\n```cjs\nconst url = require('node:url');\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(myURL.href);\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(myURL.toString());\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));\n// Prints 'https://測試/?abc'\n```","summary":"Returns a customizable serialization of a URL `String` representation of a WHATWG URL object.","examples":[{"language":"mjs","displayName":null,"code":"import url from 'node:url';\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(myURL.href);\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(myURL.toString());\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));\n// Prints 'https://測試/?abc'"},{"language":"cjs","displayName":null,"code":"const url = require('node:url');\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(myURL.href);\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(myURL.toString());\n// Prints https://a:b@xn--g6w251d/?abc#foo\n\nconsole.log(url.format(myURL, { fragment: false, unicode: true, auth: false }));\n// Prints 'https://測試/?abc'"}],"children":[]},{"kind":"method","id":"urlpathtofileurlpath-options","name":"pathToFileURL","title":"`url.pathToFileURL(path[, options])`","scope":"module","overloadOf":null,"stability":null,"added":["v10.12.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v22.1.0","v20.13.0"],"prUrl":"https://github.com/nodejs/node/pull/52509","commit":null,"description":"The `options` argument can now be used to determine how to return the `path` value."}],"signature":{"parameters":[{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The path to convert to a File URL.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"windows","type":{"text":"boolean | undefined","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":10,"end":19}]},"description":"`true` if the `path` should be\ntreated as a windows filepath, `false` for posix, and\n`undefined` for the system default.","default":"undefined","optional":true,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"URL","links":[{"name":"URL","href":"url.html#the-whatwg-url-api","start":0,"end":3}]},"description":"The file URL object."}},"description":"This function ensures that `path` is resolved absolutely, and that the URL\ncontrol characters are correctly encoded when converting into a File URL.\n\n```mjs\nimport { pathToFileURL } from 'node:url';\n\nnew URL('/foo#1', 'file:');           // Incorrect: file:///foo#1\npathToFileURL('/foo#1');              // Correct:   file:///foo%231 (POSIX)\n\nnew URL('/some/path%.c', 'file:');    // Incorrect: file:///some/path%.c\npathToFileURL('/some/path%.c');       // Correct:   file:///some/path%25.c (POSIX)\n```\n\n```cjs\nconst { pathToFileURL } = require('node:url');\nnew URL(__filename);                  // Incorrect: throws (POSIX)\nnew URL(__filename);                  // Incorrect: C:\\... (Windows)\npathToFileURL(__filename);            // Correct:   file:///... (POSIX)\npathToFileURL(__filename);            // Correct:   file:///C:/... (Windows)\n\nnew URL('/foo#1', 'file:');           // Incorrect: file:///foo#1\npathToFileURL('/foo#1');              // Correct:   file:///foo%231 (POSIX)\n\nnew URL('/some/path%.c', 'file:');    // Incorrect: file:///some/path%.c\npathToFileURL('/some/path%.c');       // Correct:   file:///some/path%25.c (POSIX)\n```","summary":"This function ensures that `path` is resolved absolutely, and that the URL control characters are correctly encoded when converting into a File URL.","examples":[{"language":"mjs","displayName":null,"code":"import { pathToFileURL } from 'node:url';\n\nnew URL('/foo#1', 'file:');           // Incorrect: file:///foo#1\npathToFileURL('/foo#1');              // Correct:   file:///foo%231 (POSIX)\n\nnew URL('/some/path%.c', 'file:');    // Incorrect: file:///some/path%.c\npathToFileURL('/some/path%.c');       // Correct:   file:///some/path%25.c (POSIX)"},{"language":"cjs","displayName":null,"code":"const { pathToFileURL } = require('node:url');\nnew URL(__filename);                  // Incorrect: throws (POSIX)\nnew URL(__filename);                  // Incorrect: C:\\... (Windows)\npathToFileURL(__filename);            // Correct:   file:///... (POSIX)\npathToFileURL(__filename);            // Correct:   file:///C:/... (Windows)\n\nnew URL('/foo#1', 'file:');           // Incorrect: file:///foo#1\npathToFileURL('/foo#1');              // Correct:   file:///foo%231 (POSIX)\n\nnew URL('/some/path%.c', 'file:');    // Incorrect: file:///some/path%.c\npathToFileURL('/some/path%.c');       // Correct:   file:///some/path%25.c (POSIX)"}],"children":[]},{"kind":"method","id":"urlurltohttpoptionsurl","name":"urlToHttpOptions","title":"`url.urlToHttpOptions(url)`","scope":"module","overloadOf":null,"stability":null,"added":["v15.7.0","v14.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.9.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/46989","commit":null,"description":"The returned object will also contain all the own enumerable properties of the `url` argument."}],"signature":{"parameters":[{"name":"url","type":{"text":"URL","links":[{"name":"URL","href":"url.html#the-whatwg-url-api","start":0,"end":3}]},"description":"The [WHATWG URL](#the-whatwg-url-api) object to convert to an options object.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Options object"}},"description":"This utility function converts a URL object into an ordinary options object as\nexpected by the [`http.request()`](http.html#httprequestoptions-callback) and [`https.request()`](https.html#httpsrequestoptions-callback) APIs.\n\n```mjs\nimport { urlToHttpOptions } from 'node:url';\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(urlToHttpOptions(myURL));\n/*\n{\n  protocol: 'https:',\n  hostname: 'xn--g6w251d',\n  hash: '#foo',\n  search: '?abc',\n  pathname: '/',\n  path: '/?abc',\n  href: 'https://a:b@xn--g6w251d/?abc#foo',\n  auth: 'a:b'\n}\n*/\n```\n\n```cjs\nconst { urlToHttpOptions } = require('node:url');\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(urlToHttpOptions(myURL));\n/*\n{\n  protocol: 'https:',\n  hostname: 'xn--g6w251d',\n  hash: '#foo',\n  search: '?abc',\n  pathname: '/',\n  path: '/?abc',\n  href: 'https://a:b@xn--g6w251d/?abc#foo',\n  auth: 'a:b'\n}\n*/\n```","summary":"This utility function converts a URL object into an ordinary options object as expected by the `http.request()` and `https.request()` APIs.","examples":[{"language":"mjs","displayName":null,"code":"import { urlToHttpOptions } from 'node:url';\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(urlToHttpOptions(myURL));\n/*\n{\n  protocol: 'https:',\n  hostname: 'xn--g6w251d',\n  hash: '#foo',\n  search: '?abc',\n  pathname: '/',\n  path: '/?abc',\n  href: 'https://a:b@xn--g6w251d/?abc#foo',\n  auth: 'a:b'\n}\n*/"},{"language":"cjs","displayName":null,"code":"const { urlToHttpOptions } = require('node:url');\nconst myURL = new URL('https://a:b@測試?abc#foo');\n\nconsole.log(urlToHttpOptions(myURL));\n/*\n{\n  protocol: 'https:',\n  hostname: 'xn--g6w251d',\n  hash: '#foo',\n  search: '?abc',\n  pathname: '/',\n  path: '/?abc',\n  href: 'https://a:b@xn--g6w251d/?abc#foo',\n  auth: 'a:b'\n}\n*/"}],"children":[]}]},{"kind":"section","id":"legacy-url-api","name":"Legacy URL API","title":"Legacy URL API","scope":"module","overloadOf":null,"stability":{"index":"3","description":"Legacy: Use the WHATWG URL API instead."},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.13.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/37784","commit":null,"description":"Deprecation revoked. Status changed to \"Legacy\"."},{"versions":["v11.0.0"],"prUrl":"https://github.com/nodejs/node/pull/22715","commit":null,"description":"This API is deprecated."}],"description":"","summary":"","examples":[],"children":[{"kind":"section","id":"legacy-urlobject","name":"Legacy urlObject","title":"Legacy `urlObject`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.13.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/37784","commit":null,"description":"Deprecation revoked. Status changed to \"Legacy\"."},{"versions":["v11.0.0"],"prUrl":"https://github.com/nodejs/node/pull/22715","commit":null,"description":"The Legacy URL API is deprecated. Use the WHATWG URL API."}],"description":"The legacy `urlObject` (`require('node:url').Url` or\n`import { Url } from 'node:url'`) is\ncreated and returned by the `url.parse()` function.","summary":"The legacy `urlObject` (`require('node:url').Url` or `import { Url } from 'node:url'`) is created and returned by the `url.parse()` function.","examples":[],"children":[{"kind":"property","id":"urlobjectauth","name":"auth","title":"`urlObject.auth`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `auth` property is the username and password portion of the URL, also\nreferred to as *userinfo*. This string subset follows the `protocol` and\ndouble slashes (if present) and precedes the `host` component, delimited by `@`.\nThe string is either the username, or it is the username and password separated\nby `:`.\n\nFor example: `'user:pass'`.","summary":"The `auth` property is the username and password portion of the URL, also referred to as _userinfo_. This string subset follows the `protocol` and double slashes (if present) and precedes the `host` component, delimited by `@`. The string is either the username, or it is the username and password separated by `:`.","examples":[],"children":[]},{"kind":"property","id":"urlobjecthash","name":"hash","title":"`urlObject.hash`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `hash` property is the fragment identifier portion of the URL including the\nleading `#` character.\n\nFor example: `'#hash'`.","summary":"The `hash` property is the fragment identifier portion of the URL including the leading `#` character.","examples":[],"children":[]},{"kind":"property","id":"urlobjecthost","name":"host","title":"`urlObject.host`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `host` property is the full lower-cased host portion of the URL, including\nthe `port` if specified.\n\nFor example: `'sub.example.com:8080'`.","summary":"The `host` property is the full lower-cased host portion of the URL, including the `port` if specified.","examples":[],"children":[]},{"kind":"property","id":"urlobjecthostname","name":"hostname","title":"`urlObject.hostname`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `hostname` property is the lower-cased host name portion of the `host`\ncomponent *without* the `port` included.\n\nFor example: `'sub.example.com'`.","summary":"The `hostname` property is the lower-cased host name portion of the `host` component _without_ the `port` included.","examples":[],"children":[]},{"kind":"property","id":"urlobjecthref","name":"href","title":"`urlObject.href`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `href` property is the full URL string that was parsed with both the\n`protocol` and `host` components converted to lower-case.\n\nFor example: `'http://user:pass@sub.example.com:8080/p/a/t/h?query=string#hash'`.","summary":"The `href` property is the full URL string that was parsed with both the `protocol` and `host` components converted to lower-case.","examples":[],"children":[]},{"kind":"property","id":"urlobjectpath","name":"path","title":"`urlObject.path`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `path` property is a concatenation of the `pathname` and `search`\ncomponents.\n\nFor example: `'/p/a/t/h?query=string'`.\n\nNo decoding of the `path` is performed.","summary":"The `path` property is a concatenation of the `pathname` and `search` components.","examples":[],"children":[]},{"kind":"property","id":"urlobjectpathname","name":"pathname","title":"`urlObject.pathname`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `pathname` property consists of the entire path section of the URL. This\nis everything following the `host` (including the `port`) and before the start\nof the `query` or `hash` components, delimited by either the ASCII question\nmark (`?`) or hash (`#`) characters.\n\nFor example: `'/p/a/t/h'`.\n\nNo decoding of the path string is performed.","summary":"The `pathname` property consists of the entire path section of the URL. This is everything following the `host` (including the `port`) and before the start of the `query` or `hash` components, delimited by either the ASCII question mark (`?`) or hash (`#`) characters.","examples":[],"children":[]},{"kind":"property","id":"urlobjectport","name":"port","title":"`urlObject.port`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `port` property is the numeric port portion of the `host` component.\n\nFor example: `'8080'`.","summary":"The `port` property is the numeric port portion of the `host` component.","examples":[],"children":[]},{"kind":"property","id":"urlobjectprotocol","name":"protocol","title":"`urlObject.protocol`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `protocol` property identifies the URL's lower-cased protocol scheme.\n\nFor example: `'http:'`.","summary":"The `protocol` property identifies the URL's lower-cased protocol scheme.","examples":[],"children":[]},{"kind":"property","id":"urlobjectquery","name":"query","title":"`urlObject.query`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `query` property is either the query string without the leading ASCII\nquestion mark (`?`), or an object returned by the [`querystring`](querystring.html) module's\n`parse()` method. Whether the `query` property is a string or object is\ndetermined by the `parseQueryString` argument passed to `url.parse()`.\n\nFor example: `'query=string'` or `{'query': 'string'}`.\n\nIf returned as a string, no decoding of the query string is performed. If\nreturned as an object, both keys and values are decoded.","summary":"The `query` property is either the query string without the leading ASCII question mark (`?`), or an object returned by the `querystring` module's `parse()` method. Whether the `query` property is a string or object is determined by the `parseQueryString` argument passed to `url.parse()`.","examples":[],"children":[]},{"kind":"property","id":"urlobjectsearch","name":"search","title":"`urlObject.search`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `search` property consists of the entire \"query string\" portion of the\nURL, including the leading ASCII question mark (`?`) character.\n\nFor example: `'?query=string'`.\n\nNo decoding of the query string is performed.","summary":"The `search` property consists of the entire \"query string\" portion of the URL, including the leading ASCII question mark (`?`) character.","examples":[],"children":[]},{"kind":"property","id":"urlobjectslashes","name":"slashes","title":"`urlObject.slashes`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"The `slashes` property is a `boolean` with a value of `true` if two ASCII\nforward-slash characters (`/`) are required following the colon in the\n`protocol`.","summary":"The `slashes` property is a `boolean` with a value of `true` if two ASCII forward-slash characters (`/`) are required following the colon in the `protocol`.","examples":[],"children":[]}]},{"kind":"method","id":"urlformaturlobject","name":"format","title":"`url.format(urlObject)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.25"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.0.0"],"prUrl":"https://github.com/nodejs/node/pull/38631","commit":null,"description":"Now throws an `ERR_INVALID_URL` exception when Punycode conversion of a hostname introduces changes that could cause the URL to be re-parsed differently."},{"versions":["v15.13.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/37784","commit":null,"description":"Deprecation revoked. Status changed to \"Legacy\"."},{"versions":["v11.0.0"],"prUrl":"https://github.com/nodejs/node/pull/22715","commit":null,"description":"The Legacy URL API is deprecated. Use the WHATWG URL API."},{"versions":["v7.0.0"],"prUrl":"https://github.com/nodejs/node/pull/7234","commit":null,"description":"URLs with a `file:` scheme will now always use the correct number of slashes regardless of `slashes` option. A falsy `slashes` option with no protocol is now also respected at all times."}],"signature":{"parameters":[{"name":"urlObject","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"A URL object (as returned by `url.parse()` or\nconstructed otherwise).","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"The `url.format()` method returns a formatted URL string derived from\n`urlObject`.\n\n```js\nconst url = require('node:url');\nurl.format({\n  protocol: 'https',\n  hostname: 'example.com',\n  pathname: '/some/path',\n  query: {\n    page: 1,\n    format: 'json',\n  },\n});\n\n// => 'https://example.com/some/path?page=1&format=json'\n```\n\nIf `urlObject` is not an object or a string, `url.format()` will throw a\n[`TypeError`](errors.html#class-typeerror).\n\nThe formatting process operates as follows:\n\n* A new empty string `result` is created.\n* If `urlObject.protocol` is a string, it is appended as-is to `result`.\n* Otherwise, if `urlObject.protocol` is not `undefined` and is not a string, an\n  [`Error`](errors.html#class-error) is thrown.\n* For all string values of `urlObject.protocol` that *do not end* with an ASCII\n  colon (`:`) character, the literal string `:` will be appended to `result`.\n* If either of the following conditions is true, then the literal string `//`\n  will be appended to `result`:\n  * `urlObject.slashes` property is true;\n  * `urlObject.protocol` begins with `http`, `https`, `ftp`, `gopher`, or\n    `file`;\n* If the value of the `urlObject.auth` property is truthy, and either\n  `urlObject.host` or `urlObject.hostname` are not `undefined`, the value of\n  `urlObject.auth` will be coerced into a string and appended to `result`\n  followed by the literal string `@`.\n* If the `urlObject.host` property is `undefined` then:\n  * If the `urlObject.hostname` is a string, it is appended to `result`.\n  * Otherwise, if `urlObject.hostname` is not `undefined` and is not a string,\n    an [`Error`](errors.html#class-error) is thrown.\n  * If the `urlObject.port` property value is truthy, and `urlObject.hostname`\n    is not `undefined`:\n    * The literal string `:` is appended to `result`, and\n    * The value of `urlObject.port` is coerced to a string and appended to\n      `result`.\n* Otherwise, if the `urlObject.host` property value is truthy, the value of\n  `urlObject.host` is coerced to a string and appended to `result`.\n* If the `urlObject.pathname` property is a string that is not an empty string:\n  * If the `urlObject.pathname` *does not start* with an ASCII forward slash\n    (`/`), then the literal string `'/'` is appended to `result`.\n  * The value of `urlObject.pathname` is appended to `result`.\n* Otherwise, if `urlObject.pathname` is not `undefined` and is not a string, an\n  [`Error`](errors.html#class-error) is thrown.\n* If the `urlObject.search` property is `undefined` and if the `urlObject.query`\n  property is an `Object`, the literal string `?` is appended to `result`\n  followed by the output of calling the [`querystring`](querystring.html) module's `stringify()`\n  method passing the value of `urlObject.query`.\n* Otherwise, if `urlObject.search` is a string:\n  * If the value of `urlObject.search` *does not start* with the ASCII question\n    mark (`?`) character, the literal string `?` is appended to `result`.\n  * The value of `urlObject.search` is appended to `result`.\n* Otherwise, if `urlObject.search` is not `undefined` and is not a string, an\n  [`Error`](errors.html#class-error) is thrown.\n* If the `urlObject.hash` property is a string:\n  * If the value of `urlObject.hash` *does not start* with the ASCII hash (`#`)\n    character, the literal string `#` is appended to `result`.\n  * The value of `urlObject.hash` is appended to `result`.\n* Otherwise, if the `urlObject.hash` property is not `undefined` and is not a\n  string, an [`Error`](errors.html#class-error) is thrown.\n* `result` is returned.\n\nAn automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/node-url-to-whatwg-url)).\n\n```bash\nnpx codemod@latest @nodejs/node-url-to-whatwg-url\n```","summary":"The `url.format()` method returns a formatted URL string derived from `urlObject`.","examples":[{"language":"js","displayName":null,"code":"const url = require('node:url');\nurl.format({\n  protocol: 'https',\n  hostname: 'example.com',\n  pathname: '/some/path',\n  query: {\n    page: 1,\n    format: 'json',\n  },\n});\n\n// => 'https://example.com/some/path?page=1&format=json'"},{"language":"bash","displayName":null,"code":"npx codemod@latest @nodejs/node-url-to-whatwg-url"}],"children":[]},{"kind":"method","id":"urlformaturlstring","name":"format","title":"`url.format(urlString)`","scope":"module","overloadOf":"urlformaturlobject","stability":{"index":"0","description":"Deprecated: Use the WHATWG URL API instead."},"added":["v0.1.25"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0"],"prUrl":"https://github.com/nodejs/node/pull/55017","commit":null,"description":"Application deprecation."}],"signature":{"parameters":[{"name":"urlString","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A string that will be passed to `url.parse()` and then\nformatted.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"`url.format(urlString)` is shorthand for `url.format(url.parse(urlString))`.\n\nBecause it invokes the deprecated [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost) internally, passing a string argument\nto `url.format()` is itself deprecated.\n\nCanonicalizing a URL string can be performed using the WHATWG URL API, by\nconstructing a new URL object and calling [`url.toString()`](#urltostring).\n\n```mjs\nimport { URL } from 'node:url';\n\nconst unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';\nconst formatted = new URL(unformatted).toString();\n\nconsole.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc\n```\n\n```cjs\nconst { URL } = require('node:url');\n\nconst unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';\nconst formatted = new URL(unformatted).toString();\n\nconsole.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc\n```","summary":"`url.format(urlString)` is shorthand for `url.format(url.parse(urlString))`.","examples":[{"language":"mjs","displayName":null,"code":"import { URL } from 'node:url';\n\nconst unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';\nconst formatted = new URL(unformatted).toString();\n\nconsole.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc"},{"language":"cjs","displayName":null,"code":"const { URL } = require('node:url');\n\nconst unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';\nconst formatted = new URL(unformatted).toString();\n\nconsole.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc"}],"children":[]},{"kind":"method","id":"urlparseurlstring-parsequerystring-slashesdenotehost","name":"parse","title":"`url.parse(urlString[, parseQueryString[, slashesDenoteHost]])`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated: Use the WHATWG URL API instead."},"added":["v0.1.25"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0"],"prUrl":"https://github.com/nodejs/node/pull/55017","commit":null,"description":"Application deprecation."},{"versions":["v19.9.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/47203","commit":null,"description":"Added support for `--pending-deprecation`."},{"versions":["v19.0.0","v18.13.0"],"prUrl":"https://github.com/nodejs/node/pull/44919","commit":null,"description":"Documentation-only deprecation."},{"versions":["v15.13.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/37784","commit":null,"description":"Deprecation revoked. Status changed to \"Legacy\"."},{"versions":["v11.14.0"],"prUrl":"https://github.com/nodejs/node/pull/26941","commit":null,"description":"The `pathname` property on the returned URL object is now `/` when there is no path and the protocol scheme is `ws:` or `wss:`."},{"versions":["v11.0.0"],"prUrl":"https://github.com/nodejs/node/pull/22715","commit":null,"description":"The Legacy URL API is deprecated. Use the WHATWG URL API."},{"versions":["v9.0.0"],"prUrl":"https://github.com/nodejs/node/pull/13606","commit":null,"description":"The `search` property on the returned URL object is now `null` when no query string is present."}],"signature":{"parameters":[{"name":"urlString","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The URL string to parse.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"parseQueryString","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, the `query` property will always\nbe set to an object returned by the [`querystring`](querystring.html) module's `parse()`\nmethod. If `false`, the `query` property on the returned URL object will be an\nunparsed, undecoded string.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"slashesDenoteHost","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If `true`, the first token after the literal\nstring `//` and preceding the next `/` will be interpreted as the `host`.\nFor instance, given `//foo/bar`, the result would be\n`{host: 'foo', pathname: '/bar'}` rather than `{pathname: '//foo/bar'}`.","default":"false","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"The `url.parse()` method takes a URL string, parses it, and returns a URL\nobject.\n\nA `TypeError` is thrown if `urlString` is not a string.\n\nA `URIError` is thrown if the `auth` property is present but cannot be decoded.\n\n`url.parse()` uses a lenient, non-standard algorithm for parsing URL\nstrings. It is prone to security issues such as [host name spoofing](https://hackerone.com/reports/678487)\nand incorrect handling of usernames and passwords. Do not use with untrusted\ninput. CVEs are not issued for `url.parse()` vulnerabilities. Use the\n[WHATWG URL](#the-whatwg-url-api) API instead, for example:\n\n```js\nfunction getURL(req) {\n  const proto = req.headers['x-forwarded-proto'] || 'https';\n  const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';\n  return new URL(`${proto}://${host}${req.url || '/'}`);\n}\n```\n\nThe example above assumes well-formed headers are forwarded from a reverse\nproxy to your Node.js server. If you are not using a reverse proxy, you should\nuse the example below:\n\n```js\nfunction getURL(req) {\n  return new URL(`https://example.com${req.url || '/'}`);\n}\n```\n\nAn automated migration is available ([source](https://github.com/nodejs/userland-migrations/tree/main/recipes/node-url-to-whatwg-url)).\n\n```bash\nnpx codemod@latest @nodejs/node-url-to-whatwg-url\n```","summary":"The `url.parse()` method takes a URL string, parses it, and returns a URL object.","examples":[{"language":"js","displayName":null,"code":"function getURL(req) {\n  const proto = req.headers['x-forwarded-proto'] || 'https';\n  const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';\n  return new URL(`${proto}://${host}${req.url || '/'}`);\n}"},{"language":"js","displayName":null,"code":"function getURL(req) {\n  return new URL(`https://example.com${req.url || '/'}`);\n}"},{"language":"bash","displayName":null,"code":"npx codemod@latest @nodejs/node-url-to-whatwg-url"}],"children":[]},{"kind":"method","id":"urlresolvefrom-to","name":"resolve","title":"`url.resolve(from, to)`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated: Use the WHATWG URL API instead."},"added":["v0.1.25"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.0.0"],"prUrl":"https://github.com/nodejs/node/pull/55017","commit":null,"description":"Deprecated again through DEP0169."},{"versions":["v15.13.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/37784","commit":null,"description":"Deprecation revoked. Status changed to \"Legacy\"."},{"versions":["v11.0.0"],"prUrl":"https://github.com/nodejs/node/pull/22715","commit":null,"description":"The Legacy URL API is deprecated. Use the WHATWG URL API."},{"versions":["v6.6.0"],"prUrl":"https://github.com/nodejs/node/pull/8215","commit":null,"description":"The `auth` fields are now kept intact when `from` and `to` refer to the same host."},{"versions":["v6.5.0","v4.6.2"],"prUrl":"https://github.com/nodejs/node/pull/8214","commit":null,"description":"The `port` field is copied correctly now."},{"versions":["v6.0.0"],"prUrl":"https://github.com/nodejs/node/pull/1480","commit":null,"description":"The `auth` fields is cleared now the `to` parameter contains a hostname."}],"signature":{"parameters":[{"name":"from","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The base URL to use if `to` is a relative URL.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"to","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The target URL to resolve.","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"The `url.resolve()` method resolves a target URL relative to a base URL in a\nmanner similar to that of a web browser resolving an anchor tag.\n\n```js\nconst url = require('node:url');\nurl.resolve('/one/two/three', 'four');         // '/one/two/four'\nurl.resolve('http://example.com/', '/one');    // 'http://example.com/one'\nurl.resolve('http://example.com/one', '/two'); // 'http://example.com/two'\n```\n\nBecause it invokes the deprecated [`url.parse()`](#urlparseurlstring-parsequerystring-slashesdenotehost) internally, `url.resolve()` is itself deprecated.\n\nTo achieve the same result using the WHATWG URL API:\n\n```js\nfunction resolve(from, to) {\n  const resolvedUrl = new URL(to, new URL(from, 'resolve://'));\n  if (resolvedUrl.protocol === 'resolve:') {\n    // `from` is a relative URL.\n    const { pathname, search, hash } = resolvedUrl;\n    return pathname + search + hash;\n  }\n  return resolvedUrl.toString();\n}\n\nresolve('/one/two/three', 'four');         // '/one/two/four'\nresolve('http://example.com/', '/one');    // 'http://example.com/one'\nresolve('http://example.com/one', '/two'); // 'http://example.com/two'\n```\n\n<a id=\"whatwg-percent-encoding\"></a>","summary":"The `url.resolve()` method resolves a target URL relative to a base URL in a manner similar to that of a web browser resolving an anchor tag.","examples":[{"language":"js","displayName":null,"code":"const url = require('node:url');\nurl.resolve('/one/two/three', 'four');         // '/one/two/four'\nurl.resolve('http://example.com/', '/one');    // 'http://example.com/one'\nurl.resolve('http://example.com/one', '/two'); // 'http://example.com/two'"},{"language":"js","displayName":null,"code":"function resolve(from, to) {\n  const resolvedUrl = new URL(to, new URL(from, 'resolve://'));\n  if (resolvedUrl.protocol === 'resolve:') {\n    // `from` is a relative URL.\n    const { pathname, search, hash } = resolvedUrl;\n    return pathname + search + hash;\n  }\n  return resolvedUrl.toString();\n}\n\nresolve('/one/two/three', 'four');         // '/one/two/four'\nresolve('http://example.com/', '/one');    // 'http://example.com/one'\nresolve('http://example.com/one', '/two'); // 'http://example.com/two'"}],"children":[]}]},{"kind":"section","id":"percent-encoding-in-urls","name":"Percent-encoding in URLs","title":"Percent-encoding in URLs","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"URLs are permitted to only contain a certain range of characters. Any character\nfalling outside of that range must be encoded. How such characters are encoded,\nand which characters to encode depends entirely on where the character is\nlocated within the structure of the URL.","summary":"URLs are permitted to only contain a certain range of characters. Any character falling outside of that range must be encoded. How such characters are encoded, and which characters to encode depends entirely on where the character is located within the structure of the URL.","examples":[],"children":[{"kind":"section","id":"legacy-api","name":"Legacy API","title":"Legacy API","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Within the Legacy API, spaces (`' '`) and the following characters will be\nautomatically escaped in the properties of URL objects:\n\n```text\n< > \" ` \\r \\n \\t { } | \\ ^ '\n```\n\nFor example, the ASCII space character (`' '`) is encoded as `%20`. The ASCII\nforward slash (`/`) character is encoded as `%3C`.","summary":"Within the Legacy API, spaces (`' '`) and the following characters will be automatically escaped in the properties of URL objects:","examples":[{"language":"text","displayName":null,"code":"< > \" ` \\r \\n \\t { } | \\ ^ '"}],"children":[]},{"kind":"section","id":"whatwg-api","name":"WHATWG API","title":"WHATWG API","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The [WHATWG URL Standard](https://url.spec.whatwg.org/) uses a more selective and fine grained approach to\nselecting encoded characters than that used by the Legacy API.\n\nThe WHATWG algorithm defines four \"percent-encode sets\" that describe ranges\nof characters that must be percent-encoded:\n\n* The *C0 control percent-encode set* includes code points in range U+0000 to\n  U+001F (inclusive) and all code points greater than U+007E (\\~).\n\n* The *fragment percent-encode set* includes the *C0 control percent-encode set*\n  and code points U+0020 SPACE, U+0022 (\"), U+003C (<), U+003E (>),\n  and U+0060 (\\`).\n\n* The *path percent-encode set* includes the *C0 control percent-encode set*\n  and code points U+0020 SPACE, U+0022 (\"), U+0023 (#), U+003C (<), U+003E (>),\n  U+003F (?), U+0060 (\\`), U+007B ({), and U+007D (}).\n\n* The *userinfo encode set* includes the *path percent-encode set* and code\n  points U+002F (/), U+003A (:), U+003B (;), U+003D (=), U+0040 (@),\n  U+005B (\\[) to U+005E(^), and U+007C (|).\n\nThe *userinfo percent-encode set* is used exclusively for username and\npasswords encoded within the URL. The *path percent-encode set* is used for the\npath of most URLs. The *fragment percent-encode set* is used for URL fragments.\nThe *C0 control percent-encode set* is used for host and path under certain\nspecific conditions, in addition to all other cases.\n\nWhen non-ASCII characters appear within a host name, the host name is encoded\nusing the [Punycode](https://tools.ietf.org/html/rfc5891#section-4.4) algorithm. Note, however, that a host name *may* contain\n*both* Punycode encoded and percent-encoded characters:\n\n```js\nconst myURL = new URL('https://%CF%80.example.com/foo');\nconsole.log(myURL.href);\n// Prints https://xn--1xa.example.com/foo\nconsole.log(myURL.origin);\n// Prints https://xn--1xa.example.com\n```","summary":"The WHATWG URL Standard uses a more selective and fine grained approach to selecting encoded characters than that used by the Legacy API.","examples":[{"language":"js","displayName":null,"code":"const myURL = new URL('https://%CF%80.example.com/foo');\nconsole.log(myURL.href);\n// Prints https://xn--1xa.example.com/foo\nconsole.log(myURL.origin);\n// Prints https://xn--1xa.example.com"}],"children":[]}]}]}