doh-resolver

1.2.12 • Public • Published

doh-resolver

A DNS-over-HTTPS resolver for Node.js.

Last version Coverage Status NPM Status

Install

$ npm install doh-resolver --save

Usage

It can be used as dns.resolve4 and/or dns.resolve6 drop-in replacement:

const DoHResolver = require('doh-resolver')
const resolver = new DoHResolver({ servers: ['1.1.1.1', '8.8.8.8'] })

resolver.resolve4('example.com', (error, addresses) => {
  if (error) throw error
  // Handle the result
})

When you specify more than one server, the result will be the fastest HTTP request into resolve.

Customize the request using your favorite HTTP client:

const DoHResolver = require('doh-resolver')
const { promisify } = require('util')

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  get: promisify(require('simple-get'))
})

Combine it with cacheable-lookup for caching lookups respecting TTL:

const CacheableLookup = require('cacheable-lookup')
const DoHResolver = require('doh-resolver')
const https = require('https')

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  onError: cb => cb(null, [])
})

const cacheable = new CacheableLookup({ resolver })

https.get('https://example.com', { lookup: cacheable.lookup }, response => {
  // Handle the response here
})

You can store the result via keyv to maximize cache HIT:

const CacheableLookup = require('cacheable-lookup')
const DoHResolver = require('doh-resolver')
const KeyvMulti = require('@keyvhq/multi')
const KeyvRedis = require('@keyvhq/redis')
const Keyv = require('@keyvhq/core')
const https = require('https')

const cache = new Keyv({
  store: new KeyvMulti({
    local: new Map(),
    remote: new KeyvRedis()
  })
})

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  onError: cb => cb(null, [])
})

const cacheable = new CacheableLookup({ resolver, cache })

https.get('https://example.com', { lookup: cacheable.lookup }, response => {
  // Handle the response here
})

If you want to debug timings, you can pass your own logger:

const DoHResolver = require('doh-resolver')

const resolver = new DoHResolver({
  servers: ['1.1.1.1', '8.8.8.8'],
  logger: require('debug-logfmt')('doh-resolver')
})

License

doh-resolver © Kiko Beats, released under the MIT License.
Authored and maintained by Kiko Beats with help from contributors.

kikobeats.com · GitHub Kiko Beats · Twitter @Kikobeats

Readme

Keywords

Package Sidebar

Install

npm i doh-resolver

Weekly Downloads

1

Version

1.2.12

License

MIT

Unpacked Size

9.29 kB

Total Files

4

Last publish

Collaborators

  • kikobeats