# prefer-global/url

Rule `node/prefer-global/url`. Enforce either `URL` or `require("url").URL`

- Source: node
- Technologies: Node.js
- Kind: style
- Needs type information: no
- Autofix: no
- Reach: 0 weekly downloads of presets that enable it
- Trend: 0% last quarter
- Rank: #1991 by reach

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `n/prefer-global/url` | no | no | package `eslint-plugin-n` | [docs](https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/prefer-global/url.md) |

## Code examples

### Incorrect: the rule reports this

```js
const { URL } = require("url")
const u = new URL(s)
```

```js
const u = new URL(s)
```

### Correct: the rule accepts this

```js
const u = new URL(s)
```

```js
const { URL } = require("url")
const u = new URL(s)
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
import n from "eslint-plugin-n";

export default [
  {
    plugins: { n },
    rules: {
      "n/prefer-global/url": "error",
    },
  },
];
```

## Related rules

- [node/prefer-global/timers](https://lintradar.dev/rules/node/prefer-global/timers.md): Enforce either global timer functions or `require("timers")`
- [node/prefer-global/url-search-params](https://lintradar.dev/rules/node/prefer-global/url-search-params.md): Enforce either `URLSearchParams` or `require("url").URLSearchParams`
- [node/prefer-global/text-encoder](https://lintradar.dev/rules/node/prefer-global/text-encoder.md): Enforce either `TextEncoder` or `require("util").TextEncoder`
- [node/prefer-import/assert-strict](https://lintradar.dev/rules/node/prefer-import/assert-strict.md): Enforce using `node:assert/strict` instead of `node:assert`.
- [node/prefer-global/text-decoder](https://lintradar.dev/rules/node/prefer-global/text-decoder.md): Enforce either `TextDecoder` or `require("util").TextDecoder`
- [node/prefer-promises/dns](https://lintradar.dev/rules/node/prefer-promises/dns.md): Enforce `require("dns").promises`

---

Web page: https://lintradar.dev/rules/node/prefer-global/url. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
