{"_id":"@darcas/smart-dns-promises","_rev":"4-4d4326d4c376e719fc194cc40d0b638b","name":"@darcas/smart-dns-promises","dist-tags":{"latest":"1.2.0"},"versions":{"1.0.0":{"name":"@darcas/smart-dns-promises","version":"1.0.0","keywords":["dns","dns-cache","dns-provider","node","node-20","node-22","resolver","smart-dns","performance","speed"],"author":{"url":"DarCas","name":"Dario Casertano","email":"dario@casertano.name"},"license":"MIT","_id":"@darcas/smart-dns-promises@1.0.0","maintainers":[{"name":"darcas","email":"dario.casertano@gmail.com"}],"homepage":"https://github.com/DarCas/smart-dns-promises","bugs":{"url":"https://github.com/DarCas/smart-dns-promises/issues"},"dist":{"shasum":"424b4e1a0f96def1ca55d31efe862aa21f8dbdcd","tarball":"https://registry.npmjs.org/@darcas/smart-dns-promises/-/smart-dns-promises-1.0.0.tgz","fileCount":15,"integrity":"sha512-aFu2TMKk3hFJb4VeTIPD/N/9ex93EmXeDkdT4pBKaX1C7R/RLd8NQZ7PvTA8rVA3i6hEj4QFJ2naWwTyS1xdRw==","signatures":[{"sig":"MEUCID1V8EBWq3iW7FYTPtP92DMypUPTEUV7FAEMukuB9XkGAiEAm04hxBPZv00KH8l4khXD9EwyRSdMvJFSmJIs+GngV1s=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":312343},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./min":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.min.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.min.js"}}}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":"20 || >= 22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./min":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.min.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.min.js"}}},"gitHead":"6b95d9c31df2cb7094869367e0bfe3ed09275542","scripts":{"cjs":"esbuild --minify --sourcemap --bundle dist/commonjs/index.js --outfile=dist/commonjs/index.min.js --format=cjs --platform=node","esm":"esbuild --minify --sourcemap --bundle dist/esm/index.js --outfile=dist/esm/index.min.js --format=esm --platform=node","test":"echo \"Error: no test specified\" && exit 1","build":"rm -rf ./dist && tshy && rm -rf ./dist/node_modules && npm run cjs && npm run esm","deploy":"npm run build && npm publish --access public"},"_npmUser":{"name":"darcas","email":"dario.casertano@gmail.com"},"repository":{"url":"git+https://github.com/DarCas/smart-dns-promises.git","type":"git"},"_npmVersion":"10.9.0","description":"A simple and efficient DNS resolver with caching and configurable DNS providers for Node.js 20 and 22 or above, designed to enhance DNS resolution performance in environments using libraries like fetch or axios.","directories":{},"_nodeVersion":"22.12.0","dependencies":{"lru-cache":"^11.0.2"},"_hasShrinkwrap":false,"devDependencies":{"tshy":"^3.0.2","esbuild":"^0.24.2","typescript":"^5.7.2","@types/node":"^22.10.2"},"_npmOperationalInternal":{"tmp":"tmp/smart-dns-promises_1.0.0_1735223166433_0.8821257281391714","host":"s3://npm-registry-packages-npm-production"}},"1.1.0":{"name":"@darcas/smart-dns-promises","version":"1.1.0","keywords":["dns","dns-cache","dns-provider","node","node-20","node-22","resolver","smart-dns","performance","speed"],"author":{"url":"DarCas","name":"Dario Casertano","email":"dario@casertano.name"},"license":"MIT","_id":"@darcas/smart-dns-promises@1.1.0","maintainers":[{"name":"darcas","email":"dario.casertano@gmail.com"}],"homepage":"https://github.com/DarCas/smart-dns-promises","bugs":{"url":"https://github.com/DarCas/smart-dns-promises/issues"},"dist":{"shasum":"7cddf8bcc6352aee9d0b3cc37585ca24f525a6af","tarball":"https://registry.npmjs.org/@darcas/smart-dns-promises/-/smart-dns-promises-1.1.0.tgz","fileCount":15,"integrity":"sha512-qZogEwphk8Ydo8/P6zQQZabELmI5ZwQB6c8GwiN6mWo8Zk5qv+sG5RttURqL4KvDahaYbEqVTTdesFvzg/bNXA==","signatures":[{"sig":"MEUCIGxQQxhZwFh9SH5LFvnbYSN3qp1WaHIh9mUSi23LIrIPAiEA7HsFORvGOc+8/49Fn0Xa+iXQ4u6yTow8fhLog0y5Q/0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@darcas%2fsmart-dns-promises@1.1.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":83861},"main":"./dist/commonjs/index.js","tshy":{"exports":{".":"./src/index.ts","./min":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.min.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.min.js"}}}},"type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":"20 || >= 22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./min":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.min.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.min.js"}}},"gitHead":"ff25d9b51302396dece0cc2fb03b7572a2a88900","scripts":{"cjs":"esbuild --minify --sourcemap --bundle dist/commonjs/index.js --outfile=dist/commonjs/index.min.js --format=cjs --platform=node","esm":"esbuild --minify --sourcemap --bundle dist/esm/index.js --outfile=dist/esm/index.min.js --format=esm --platform=node","test":"vitest run","build":"rm -rf ./dist && tshy && rm -rf ./dist/node_modules && npm run cjs && npm run esm","deploy":"npm run build && npm publish --access public"},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4bc76412-28a3-4324-b648-062d805615ec"}},"repository":{"url":"git+https://github.com/DarCas/smart-dns-promises.git","type":"git"},"_npmVersion":"11.17.0","description":"![NPM Last Update](https://img.shields.io/npm/last-update/%40darcas%2Fsmart-dns-promises?style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/%40darcas%2Fsmart-dns-promises?style=for-the-badge) ![NPM Downloads](https://img.shields.io/npm/dy/%4","directories":{},"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"devDependencies":{"tshy":"^3.0.2","vitest":"^4.1.11","esbuild":"^0.24.2","typescript":"^5.7.2","@types/node":"^22.10.2"},"_npmOperationalInternal":{"tmp":"tmp/smart-dns-promises_1.1.0_1787317758267_0.9078781670120282","host":"s3://npm-registry-packages-npm-production"}},"1.1.1":{"name":"@darcas/smart-dns-promises","version":"1.1.1","keywords":["dns","dns-cache","dns-provider","node","node-20","node-22","resolver","smart-dns","performance","speed"],"author":{"url":"DarCas","name":"Dario Casertano","email":"dario@casertano.name"},"license":"MIT","_id":"@darcas/smart-dns-promises@1.1.1","maintainers":[{"name":"darcas","email":"dario.casertano@gmail.com"}],"homepage":"https://github.com/DarCas/smart-dns-promises","bugs":{"url":"https://github.com/DarCas/smart-dns-promises/issues"},"dist":{"shasum":"ee435b9f88886ff2c0492388829b4130b0bc9fa0","tarball":"https://registry.npmjs.org/@darcas/smart-dns-promises/-/smart-dns-promises-1.1.1.tgz","fileCount":15,"integrity":"sha512-tmBNgDyG8pK4wtkyDgIn8yICFb2qEmWNsx5uBAiTtm2H2VTdmW7ERg1j1YOHDTJsjRK0aXVAZ7+KQHl1INlamw==","signatures":[{"sig":"MEQCIAOC+an69eW0XEUlC1McfO9rbQoGi5ikY7pGavQHv5OYAiANrZXsZwf0OThBAtte3THIO8ZyLYUe62+BiwwrCO8spg==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@darcas%2fsmart-dns-promises@1.1.1","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":83938},"main":"./dist/commonjs/index.js","type":"module","types":"./dist/commonjs/index.d.ts","module":"./dist/esm/index.js","engines":{"node":"20 || >= 22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./min":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.min.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.min.js"}}},"gitHead":"d23ca727c4befecdaf74a0d1c8235623e8017f8e","scripts":{"cjs":"esbuild --minify --sourcemap --bundle dist/commonjs/index.js --outfile=dist/commonjs/index.min.js --format=cjs --platform=node","esm":"esbuild --minify --sourcemap --bundle dist/esm/index.js --outfile=dist/esm/index.min.js --format=esm --platform=node","test":"vitest run","build":"rm -rf ./dist && npm run build:esm && npm run build:esm-pkg && npm run build:cjs && npm run cjs && npm run esm","deploy":"npm run build && npm publish --access public","build:cjs":"tsc --outDir dist/commonjs --module commonjs --moduleResolution node10 && node -e \"const fs = require('fs'); fs.writeFileSync('dist/commonjs/package.json', JSON.stringify({ type: 'commonjs' }, null, 2) + '\\n')\"","build:esm":"tsc --outDir dist/esm","build:esm-pkg":"node -e \"require('fs').writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' }, null, 2) + '\\n')\""},"_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4bc76412-28a3-4324-b648-062d805615ec"}},"repository":{"url":"git+https://github.com/DarCas/smart-dns-promises.git","type":"git"},"_npmVersion":"11.17.0","description":"![NPM Last Update](https://img.shields.io/npm/last-update/%40darcas%2Fsmart-dns-promises?style=for-the-badge) ![NPM Version](https://img.shields.io/npm/v/%40darcas%2Fsmart-dns-promises?style=for-the-badge) ![NPM Downloads](https://img.shields.io/npm/dy/%4","directories":{},"_nodeVersion":"24.19.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.1.11","esbuild":"^0.24.2","typescript":"^5.7.2","@types/node":"^22.10.2"},"_npmOperationalInternal":{"tmp":"tmp/smart-dns-promises_1.1.1_1787319100712_0.8142709751982466","host":"s3://npm-registry-packages-npm-production"}},"1.2.0":{"_id":"@darcas/smart-dns-promises@1.2.0","bugs":{"url":"https://github.com/DarCas/smart-dns-promises/issues"},"dist":{"shasum":"d1c434a882f92236e3fe7163f9a972b5940480d0","tarball":"https://registry.npmjs.org/@darcas/smart-dns-promises/-/smart-dns-promises-1.2.0.tgz","fileCount":15,"integrity":"sha512-eAJ6OOgboqcq0bwin+6a0IBMxgWaEkiJZFIHSuraFaYjbBLbUNWUSm44BZakD+IZt9JtxCTybtl3qg8BLOwXNw==","signatures":[{"sig":"MEQCIAiofenKdg0IWWt/kqah+DP6NWFmdgFrb9lZxyc1kc1ZAiBXewqXEyfLvtwoQfcdEJCcrRYSDnigT1fYArof7q2ORQ==","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"},{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEUCIQClUkC17GiZldCntwMnJS3dr4FFmDxhOOon2nbYH/QEUQIgNWD3acSbluiIHhGgDUKTjFahEVZSGI3Gc7obePAZGiU="}],"attestations":{"url":"https://registry.npmjs.org/-/npm/v1/attestations/@darcas%2fsmart-dns-promises@1.2.0","provenance":{"predicateType":"https://slsa.dev/provenance/v1"}},"unpackedSize":93347},"main":"./dist/commonjs/index.js","name":"@darcas/smart-dns-promises","type":"module","types":"./dist/commonjs/index.d.ts","author":{"url":"DarCas","name":"Dario Casertano","email":"dario@casertano.name"},"module":"./dist/esm/index.js","engines":{"node":"20 || >= 22"},"exports":{".":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.js"}},"./min":{"import":{"types":"./dist/esm/index.d.ts","default":"./dist/esm/index.min.js"},"require":{"types":"./dist/commonjs/index.d.ts","default":"./dist/commonjs/index.min.js"}}},"gitHead":"5295aa42c9ad4762be26cf59921cf56d57b6c8b2","license":"MIT","scripts":{"cjs":"esbuild --minify --sourcemap --bundle dist/commonjs/index.js --outfile=dist/commonjs/index.min.js --format=cjs --platform=node","esm":"esbuild --minify --sourcemap --bundle dist/esm/index.js --outfile=dist/esm/index.min.js --format=esm --platform=node","test":"vitest run","build":"rm -rf ./dist && npm run build:esm && npm run build:esm-pkg && npm run build:cjs && npm run cjs && npm run esm","deploy":"npm run build && npm publish --access public","build:cjs":"tsc --outDir dist/commonjs --module commonjs --moduleResolution node10 && node -e \"const fs = require('fs'); fs.writeFileSync('dist/commonjs/package.json', JSON.stringify({ type: 'commonjs' }, null, 2) + '\\n')\"","build:esm":"tsc --outDir dist/esm","build:esm-pkg":"node -e \"require('fs').writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' }, null, 2) + '\\n')\""},"version":"1.2.0","_npmUser":{"name":"GitHub Actions","email":"npm-oidc-no-reply@github.com","trustedPublisher":{"id":"github","oidcConfigId":"oidc:4bc76412-28a3-4324-b648-062d805615ec"}},"homepage":"https://smartdns.os.darcas.app","keywords":["dns","dns-resolver","dns-cache","dns-lookup","nodejs","typescript","axios","fetch","caching","ttl","stale-while-revalidate","zero-dependency","deduplication","performance"],"repository":{"url":"git+https://github.com/DarCas/smart-dns-promises.git","type":"git"},"_npmVersion":"11.19.0","description":"Zero-dependency DNS resolver for Node.js with TTL-aware caching, request deduplication and stale-while-revalidate — 9 configurable providers, built for fetch and axios.","directories":{},"maintainers":[{"name":"darcas","email":"dario.casertano@gmail.com"}],"_nodeVersion":"24.20.0","_hasShrinkwrap":false,"devDependencies":{"vitest":"^4.1.11","esbuild":"^0.24.2","typescript":"^5.7.2","@types/node":"^22.10.2"},"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/smart-dns-promises_1.2.0_1789909871369_0.5878810420264651"}}},"time":{"created":"2024-12-26T14:26:06.344Z","modified":"2026-09-20T13:11:11.819Z","1.0.0":"2024-12-26T14:26:06.640Z","1.1.0":"2026-08-21T13:09:18.430Z","1.1.1":"2026-08-21T13:31:40.913Z","1.2.0":"2026-09-20T13:11:11.452Z"},"bugs":{"url":"https://github.com/DarCas/smart-dns-promises/issues"},"author":{"url":"DarCas","name":"Dario Casertano","email":"dario@casertano.name"},"license":"MIT","homepage":"https://smartdns.os.darcas.app","keywords":["dns","dns-resolver","dns-cache","dns-lookup","nodejs","typescript","axios","fetch","caching","ttl","stale-while-revalidate","zero-dependency","deduplication","performance"],"repository":{"url":"git+https://github.com/DarCas/smart-dns-promises.git","type":"git"},"description":"Zero-dependency DNS resolver for Node.js with TTL-aware caching, request deduplication and stale-while-revalidate — 9 configurable providers, built for fetch and axios.","maintainers":[{"name":"darcas","email":"dario.casertano@gmail.com"}],"readme":"# SmartDns\n\n![NPM Last Update](https://img.shields.io/npm/last-update/%40darcas%2Fsmart-dns-promises?style=for-the-badge)\n![NPM Version](https://img.shields.io/npm/v/%40darcas%2Fsmart-dns-promises?style=for-the-badge)\n![NPM Downloads](https://img.shields.io/npm/dy/%40darcas%2Fsmart-dns-promises?style=for-the-badge)\n\n![NPM License](https://img.shields.io/npm/l/%40darcas%2Fsmart-dns-promises?style=for-the-badge)\n\n[![Buy me a coffee](https://img.shields.io/badge/buy_me_a_coffee-%E2%9D%A4%EF%B8%8F-FEEBE7?style=for-the-badge&labelColor=FF0000)](https://www.paypal.com/donate/?hosted_button_id=YZQDE3TEYDBWA)\n\nA simple and efficient DNS resolver with caching and configurable DNS providers for Node.js 20 and 22 or above.\n\nThe purpose of this library is to increase the speed and performance of DNS resolution in Node.js. In environments where requests are made using libraries like [fetch](https://github.com/node-fetch/node-fetch) or [axios](https://github.com/axios/axios), this can be very useful.\n\n## Features\n\n- DNS resolution with caching for faster lookups (zero runtime dependencies).\n- Cache entries expire according to the **real DNS record TTL** (configurable min/max clamp).\n- Negative caching of failed lookups to avoid hammering the resolver on down hosts.\n- In-flight deduplication: concurrent lookups for the same hostname trigger a single DNS query.\n- Optional stale-while-revalidate: expired entries are served immediately and refreshed in background.\n- Lookup statistics: hits, misses, errors, revalidations and average resolve time.\n- Supports configurable DNS providers: AdGuard, CloudFlare, Comodo, DNS.WATCH, Google, OpenDNS, Quad9, Verisign, and Yandex.\n- Allows custom result order for DNS resolutions: IPv4 first, IPv6 first, or verbatim, plus `ipv4`/`ipv6` family selection.\n- Singleton pattern to ensure only one instance of the resolver is used.\n- Manual configuration of DNS server addresses.\n\n## Installation\n\nTo install the `SmartDns` in your project, run the following npm command:\n\n```bash\nnpm install @darcas/smart-dns-promises\n```\n\nOr, if you're using yarn:\n\n```bash\nyarn add @darcas/smart-dns-promises\n```\n\n## Usage\n\n> In environments such as APIs, it is recommended to call `factory` as early as possible in the application lifecycle to benefit from Node.js's DNS system configuration.\n> See [Process-wide behaviour](#process-wide-behaviour) for details.\n \n### Creating an instance\n\nYou can create or retrieve a singleton instance of the `SmartDns` class using the `factory` method. This method also allows you to configure the DNS provider, result order, and cache time-to-live (TTL).\n\n```js\nimport { SmartDns } from '@darcas/smart-dns-promises'\n\n// Create or get the singleton instance\nconst dns = SmartDns.factory();\n\n// Optionally, configure DNS provider and result order\nconst dnsWithConfig = SmartDns.factory('Google', 'ipv4first', 600000);\n\n// Advanced options (4th argument)\nconst dnsAdvanced = SmartDns.factory('CloudFlare', 'ipv4first', undefined, {\n    family: 'ipv6',     // resolve AAAA records instead of A records\n    maxTtl: 3600000,    // clamp for record TTLs coming from DNS (ms)\n    minTtl: 1000,       // clamp for record TTLs coming from DNS (ms)\n    negativeTtl: 30000, // how long failed lookups are negatively cached (ms)\n    onStats: (stats) => console.log(stats),\n    swr: true,          // serve stale entries and refresh in background\n});\n```\n\n> Configuration passed to `factory` after the first call is ignored, because the singleton has already been created.\n\n### Process-wide behaviour\n\n`SmartDns` intentionally configures **Node's process-global DNS system** (`node:dns`):\n\n- `setProvider()` and `setServers()` replace the resolver servers for the **whole process**, not just for this library.\n- The `resultOrder` argument of `factory`/the constructor calls Node's `dns.setDefaultResultOrder()`, which is global too.\n\nThis is by design: every HTTP client in the application — axios, fetch, or any other dependency performing DNS lookups — benefits from (and is affected by) the configured provider. For this reason, call `factory()` as **early as possible** in the application lifecycle, ideally once, so your entire Node.js software runs with a consistent and fast DNS configuration.\n\nIf multiple configurations are applied, the last one wins for the whole process.\n\n### Statistics\n\nEvery lookup updates the instance counters, available via the `stats` getter:\n\n```js\nconst { hits, misses, errors, revalidations, avgResolveMs } = dns.stats\n```\n### Setting the DNS provider\n\nYou can set the DNS provider using the `setProvider` method with any `DnsProvider` member.\n\n```js\ndns.setProvider('CloudFlare');\n```\n\nAvailable providers:\n\n| Provider | Servers |\n|---|---|\n| AdGuard | `94.140.14.14`, `94.140.15.15` |\n| CloudFlare | `1.1.1.1`, `1.0.0.1` |\n| Comodo | `8.26.56.26`, `8.20.247.20` |\n| DNS.WATCH | `84.200.69.80`, `84.200.70.40` |\n| Google | `8.8.8.8`, `8.8.4.4` |\n| OpenDNS | `208.67.222.222`, `208.67.220.220` |\n| Quad9 | `9.9.9.9`, `149.112.112.112` |\n| Verisign | `64.6.64.6`, `64.6.65.6` |\n| Yandex | `77.88.8.8`, `77.88.8.1` |\n\n### Setting the result Order\n\nThe result order for DNS resolutions can be configured as follows:\n\n- **`ipv4first`**: IPv4 addresses are preferred and returned before IPv6 addresses.\n- **`ipv6first`**: IPv6 addresses are preferred and returned before IPv4 addresses.\n- **`verbatim`**: The DNS resolution returns results in the exact order as returned by the DNS provider without preference for IPv4 or IPv6.\n\n### Resolving URLs\n\nUse the `resolver` method to resolve a URL and get its IP address, hostname, and updated URL with the hostname replaced by the IP address.\n\n```js\nconst result = await dns.resolver('https://example.com');\nconsole.log(result.address);  // Resolved IP address\nconsole.log(result.hostname); // Original hostname\nconsole.log(result.urlReplaced); // URL with IP address instead of hostname\n```\n\n### Manually setting DNS servers\n\nYou can manually set DNS server IP addresses using the `setServers` method.\n\n```js\ndns.setServers([\n  '8.8.8.8', \n  '8.8.4.4',\n]);\n```\n\n## Error Handling\n\nThe library throws two types of errors:\n\n1. **SmartDnsProviderError**: Thrown when an unsupported DNS provider is used.\n2. **SmartDnsResolverError**: Thrown when there is an issue with resolving a URL (e.g., invalid URL format).\n\n## Example with Axios\n\nThis example shows how to use the package along with Axios to automatically resolve the hostname in requests to the corresponding IP address and adjust the request headers.\n\n```ts\nimport { DnsProvider, SmartDns } from '@darcas/smart-dns-promises'\nimport { default as _axios, InternalAxiosRequestConfig } from 'axios';\n\nconst axios = _axios.create()\nconst dns = SmartDns.factory(DnsProvider.OpenDNS)\n\naxios.interceptors.request.use(async (config: InternalAxiosRequestConfig): Promise<InternalAxiosRequestConfig> => {\n    const {\n        address,\n        hostname,\n        urlReplaced,\n    } = await dns.resolver(config.url)\n\n    config.headers = {\n        ...config.headers ?? {},\n        Host: hostname,\n    } \n    config.url = urlReplaced\n\n    return config\n})\n```\n\n## Example with fetch\n\nThe same idea with the global `fetch`: resolve once, request the IP directly and pass the original hostname in the `Host` header.\n\n```ts\nimport { SmartDns } from '@darcas/smart-dns-promises'\n\nconst dns = SmartDns.factory()\n\nasync function smartFetch(url: string, init: RequestInit = {}): Promise<Response> {\n    const { urlReplaced } = await dns.resolver(url)\n\n    return fetch(urlReplaced, {\n        ...init,\n        headers: {\n            ...init.headers,\n            Host: new URL(url).hostname,\n        },\n    })\n}\n```\n\nTwo things to keep in mind:\n\n1. Replacing the hostname with the IP address means the TLS handshake is performed against the IP: this works out of the box with plain HTTP endpoints or controlled environments, but on public HTTPS endpoints the certificate is issued to the hostname, so the request will fail certificate validation. For HTTPS use cases prefer the axios example above.\n2. Thanks to the cache, subsequent requests to the same host skip the DNS lookup entirely.\n\n## Contributing\n\nIf you'd like to contribute to the project, feel free to fork it and create a pull request. Please ensure that your changes are well-tested and properly documented.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n---\n\nMade with ❤️ by [Dario Casertano (DarCas)](https://github.com/DarCas).\n","readmeFilename":"README.md"}