# node:url

`node:url` надає застарілі допоміжні засоби URL з Node поряд із глобальними
конструкторами [`URL`](/docs/api-whatwg-url) і
[`URLSearchParams`](/docs/api-whatwg-url).

```js
const url = require("node:url");
const parsed = url.parse("https://user:pw@example.com:8080/a?x=1#h", true);
parsed.host;    // "example.com:8080"
parsed.query.x; // "1"

url.resolve("https://example.com/a/b/c", "../x");
// "https://example.com/a/x"
```

| Допоміжний засіб | Результат |
|---|---|
| `parse(value, parseQueryString?, slashesDenoteHost?)` | Застарілий `UrlObject`; дублікати ключів під час розбору стають масивами. |
| `format(value)` | Рядок, побудований із застарілого об'єкта або WHATWG `URL`. |
| `resolve(from, to)` | Розв'язаний рядок URL. |
| `resolveObject(from, to)` | Розв'язаний застарілий об'єкт. |
| `domainToASCII()` / `domainToUnicode()` | Перетворення IDN. |
| `fileURLToPath()` / `pathToFileURL()` | Перетворення між файловим URL та абсолютним шляхом. |
| `urlToHttpOptions()` | Параметри для API HTTP-запитів Node. |

`url.URL === globalThis.URL` і
`url.URLSearchParams === globalThis.URLSearchParams`. У новому коді віддавайте
перевагу цим конструкторам WHATWG, а не застарілому розбирачу.

## Див. також

- [API URL Node.js](https://nodejs.org/api/url.html)
- [WHATWG URL](/docs/api-whatwg-url)

<!-- api-reference:start d3778894af08 -->
## Reference

**Status:** Full · 40 of 42 suite tests pass (95.2%) · since 1.1.0

### Exports

| Export | Kind | Status | Notes |
| --- | --- | --- | --- |
| `parse()` | function | Full | Parses a URL string into a UrlObject (legacy API) |
| `format()` | function | Full | Formats a URL object or WHATWG URL back into a string |
| `resolve()` | function | Full | Resolves a target URL relative to a base URL (legacy API) |
| `URL` | property | Full | The WHATWG URL class (same as global URL) |
| `URLSearchParams` | property | Full | The WHATWG URLSearchParams class (same as global URLSearchParams) |
| `domainToASCII()` | function | Full | Converts a Unicode domain name to its ASCII (Punycode) representation |
| `domainToUnicode()` | function | Full | Converts an ASCII (Punycode) domain name to Unicode |
| `fileURLToPath()` | function | Full | Converts a file: URL to a filesystem path string |
| `pathToFileURL()` | function | Full | Converts an absolute filesystem path to a file: URL |
| `urlToHttpOptions()` | function | Full | Returns an object with URL components suitable for use with http.request() |
| `resolveObject()` | function | Full | Resolves a relative URL against a source URL object, similar to a browser resolving an anchor tag |

**Tests:** [node-api `node:url`](https://github.com/elide-dev/testsuite/blob/main/reports/1.6.0%2B6e718933f/4cbcae6c33a8/node-api/node-api.md): 40 pass, 2 fail, 0 error, 3 skipped. Failing: `test-whatwg-url-custom-inspect.js`, `test-whatwg-url-custom-parsing.js`.
<!-- api-reference:end -->
