diff --git a/README.md b/README.md index 37b6226..4ed7b2c 100644 --- a/README.md +++ b/README.md @@ -2,24 +2,16 @@ **@layered/dns-records** is a DNS helper library than can quickly discover and retrieve all DNS records for a domain. -Uses Cloudflare or Google DNS, has a built-in list of subdomains to test for and support for auto-discovering more subdomains. - -→ See it in action here https://dmns.app - -## Highlights * Retrieves DNS records for a domain * Discovers (almost) all A, AAAA, CNAME, and TXT for a domain * Detects wildcard `*` records * Option to specify extra subdomains to check for * Provides results in common format, see `DnsRecord` -* Works in all JavaScript runtimes: Browsers, NodeJS, CloudFlare Workers, Deno, Bun, etc - -## Getting Started +* Works in all JavaScript runtimes: Browsers, Node.js, CloudFlare Workers, Deno, Bun, etc -#### Requirements +→ See it in action here https://dmns.app -- `fetch` as a global -- `dig` command for DNS lookups, if using `node-dig` resolver. https://linux.die.net/man/1/dig +## Getting Started #### Installation @@ -37,32 +29,45 @@ const txtRecords = await getDnsRecords('google.com', 'TXT') const allRecords = await getAllDnsRecords('x.com') ``` +## DNS Resolvers + +Here is the list of supported DNS resolvers: + +|Name|JS Runtime|Notes| +|:--|:--|:--| +|`cloudflare-dns`|Works on all|Requires `fetch` as global| +|`google-dns`|Works on all|Requires `fetch` as global| +|`node-dns`|Works only in Node.js|Uses [Node.js DNS module](https://nodejs.org/api/dns.html)| +|`node-dig`|Works only in Node.js|Uses [`dig` command](https://www.ibm.com/docs/en/aix/7.3?topic=d-dig-command)| +|`deno-dns`|Works only in Deno|Uses [Deno.resolveDns]([https://nodejs.org/api/dns.html](https://deno.land/api?s=Deno.resolveDns))| + ## Client API -- [`getDnsRecords(hostname: string, type: string = 'A', resolver = 'cloudflare-dns')`](#dns-records-by-type) - Get DNS records for a hostname -- [`getAllDnsRecords(domain: string, options)`](#all-dns-records) - Get all DNS records for a domain +- [`getDnsRecords(hostname: string, type: string = 'A', resolver?)`](#dns-records-by-type) - Get DNS records for a hostname +- [`getAllDnsRecords(domain: string, options: GetAllDnsRecordsOptions)`](#all-dns-records) - Get all DNS records for a domain - [`getAllDnsRecordsStream(domain: string, options): ReadableStream`](#all-dns-records-stream) #### DNS Records by type -`getDnsRecords(name: string, type: string = 'A', resolver = 'cloudflare-dns'): Promise` +`getDnsRecords(name: string, type: string = 'A', resolver?): Promise` |Params|type|default|description| |-----|---|---|---| |name |string| |hostname. Ex: `'x.com'` or `email.apple.com`| |type |string|`A`|record type: Ex: `'TXT'`, `'MX'`, `'CNAME'`| -|resolver |string|`cloudflare-dns`|DNS resolver to use: `cloudflare-dns`, `google-dns`, `node-dig`| - +|resolver |string| |DNS resolver to use, see resolvers above. If not set, the best match for current runtime will be used| ```js import { getDnsRecords } from '@layered/dns-records' -const records1 = await getDnsRecords('google.com') +const records1 = await getDnsRecords('google.com', 'A') console.log('DNS A records', records1) const records2 = await getDnsRecords('google.com', 'TXT') console.log('DNS TXT records', records2) ``` + Returns a promise which resolves with an `DnsRecord[]` of records found: + ```js [ { name: 'google.com.', ttl: 608, @@ -72,23 +77,25 @@ Returns a promise which resolves with an `DnsRecord[]` of records found: ] ``` - #### All DNS records -`getAllDnsRecords(domain: string, options): Promise` +`getAllDnsRecords(domain: string, options: GetAllDnsRecordsOptions): Promise` -|Params|type|default|description| -|-----|---|---|---| -|domain|string| |Valid domain name, ex: `'google.com'`| -|options|object| | | +|Params|type|description| +|-----|---|---| +|domain|string|Valid domain name, ex: `'google.com'`| +|options|object|see `GetAllDnsRecordsOptions`| ```js import { getAllDnsRecords } from '@layered/dns-records' -const allRecords = await getAllDnsRecords('x.com') +const allRecords = await getAllDnsRecords('x.com', { + resolver: 'cloudflare-dns', + commonSubdomainsCheck: true, +}) console.log('DNS all records', allRecords) ``` -Returns a Promise which resolves with `DnsRecord[]` of records found: +Returns a Promise which resolves with `DnsRecord[]` of all records found: ```js [ { name: 'x.com.', ttl: 3600, type: 'NS', data: 'ns71.domaincontrol.com.' }, { name: 'x.com.', ttl: 3600, type: 'NS', data: 'ns72.domaincontrol.com.' },