Socket
Socket
Sign inDemoInstall

@multiformats/dns

Package Overview
Dependencies
15
Maintainers
10
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @multiformats/dns

Resolve DNS queries with browser fallback


Version published
Weekly downloads
24K
increased by12.04%
Maintainers
10
Install size
2.82 MB
Created
Weekly downloads
 

Changelog

Source

1.0.6 (2024-04-06)

Bug Fixes

  • cloudflare dns only supports string type (#7) (a49bb37)

Readme

Source

@multiformats/dns

multiformats.io codecov CI

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.

Example - Using the default resolver

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

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

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

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

$ npm i @multiformats/dns

Browser <script> tag

Loading this module through a script tag will make it's exports available as MultiformatsDns in the global namespace.

<script src="https://unpkg.com/@multiformats/dns/dist/index.min.js"></script>

API Docs

License

Licensed under either of

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.

FAQs

Last updated on 06 Apr 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc