https://github.com/multiformats/js-dns
Resolve DNS queries with browser fallback
https://github.com/multiformats/js-dns
Last synced: about 1 year ago
JSON representation
Resolve DNS queries with browser fallback
- Host: GitHub
- URL: https://github.com/multiformats/js-dns
- Owner: multiformats
- License: other
- Created: 2024-03-08T15:37:51.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-04-28T16:00:58.000Z (about 1 year ago)
- Last Synced: 2025-06-05T20:04:31.693Z (about 1 year ago)
- Language: TypeScript
- Size: 93.8 KB
- Stars: 1
- Watchers: 11
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @multiformats/dns
[](http://multiformats.io)
[](https://codecov.io/gh/multiformats/js-dns)
[](https://github.com/multiformats/js-dns/actions/workflows/js-test-and-release.yml?query=branch%3Amain)
> Resolve DNS queries with browser fallback
# About
Query DNS records using `node:dns`, DNS over HTTP and/or DNSJSON over HTTP.
A list of publicly accessible servers can be found [here](https://github.com/curl/curl/wiki/DNS-over-HTTPS#publicly-available-servers).
## Example - Using the default resolver
```TypeScript
import { dns } from '@multiformats/dns'
const resolver = dns()
// resolve A records with a 5s timeout
const result = await dns.query('google.com', {
signal: AbortSignal.timeout(5000)
})
```
## Example - Using per-TLD resolvers
```TypeScript
import { dns } from '@multiformats/dns'
import { dnsJsonOverHttps } from '@multiformats/dns/resolvers'
const resolver = dns({
resolvers: {
// will only be used to resolve `.com` addresses
'com.': dnsJsonOverHttps('https://cloudflare-dns.com/dns-query'),
// this can also be an array, resolvers will be shuffled and tried in
// series
'net.': [
dnsJsonOverHttps('https://dns.google/resolve'),
dnsJsonOverHttps('https://dns.pub/dns-query')
],
// will only be used to resolve all other addresses
'.': dnsJsonOverHttps('https://dnsforge.de/dns-query'),
}
})
```
## Example - Query for specific record types
```TypeScript
import { dns, RecordType } from '@multiformats/dns'
const resolver = dns()
// resolve only TXT records
const result = await dns.query('google.com', {
types: [
RecordType.TXT
]
})
```
## Caching
Individual Aanswers are cached so. If you make a request, for which all
record types are cached, all values will be pulled from the cache.
If any of the record types are not cached, a new request will be resolved as
if none of the records were cached, and the cache will be updated to include
the new results.
## Example - Ignoring the cache
```TypeScript
import { dns, RecordType } from '@multiformats/dns'
const resolver = dns()
// do not used cached results, always resolve a new query
const result = await dns.query('google.com', {
cached: false
})
```
# Install
```console
$ npm i @multiformats/dns
```
## Browser `` tag
Loading this module through a script tag will make it's exports available as `MultiformatsDns` in the global namespace.
```html
<script src="https://unpkg.com/@multiformats/dns/dist/index.min.js">
```
# API Docs
-
# License
Licensed under either of
- Apache 2.0, ([LICENSE-APACHE](LICENSE-APACHE) / )
- MIT ([LICENSE-MIT](LICENSE-MIT) / )
# Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.