Registry / http-networking / dns-over-http

dns-over-http

JSON →
library0.2.0jsnpmunverified

DNS over HTTPS (DoH) client and middleware for Node.js. Version 0.2.0 provides both a server middleware for `http.createServer()` and a client for querying DNS via HTTPS. It uses centralized DNS servers (e.g., Quad9, Google, Cloudflare) and caches answers. This is an early-stage work-in-progress with limited features and no active maintenance. It differs from mature DoH libraries by offering a simple middleware interface and low-level wire format (dns-packet) support.

npm install dns-over-http
INSTALL
IMPORT
SIG · DNS-OVER-HTTP
D
dns-over-http
http-networkingjavascriptv0.2.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

doh
const doh = require('dns-over-http')
import doh from 'dns-over-http'
CJS module; ESM import may not work without bundler or esm package.
doh
const { default: doh } = await import('dns-over-http')
If using ESM, dynamic import with .default may be required.
doh.query
const doh = require('dns-over-http'); doh.query({url}, questions, callback)
doh.query('/dns-query', questions, callback)
First argument is an options object (including url), not a path string.
doh(opts)
const handler = doh({ servers: ['1.1.1.1'] })
const handler = doh.createServer({ servers: ['1.1.1.1'] })
doh() returns a request handler directly; no createServer method.

Creates a DoH server with HTTPS and performs two DNS queries via client.

const https = require('https'); const doh = require('dns-over-http'); const server = https.createServer({ cert: process.env.SSL_CERT || '', key: process.env.SSL_KEY || '' }, doh({ servers: ['9.9.9.9', '8.8.8.8', '1.1.1.1'], maxAge: 600000 })); server.listen(3000, () => { console.log('DoH server listening on port 3000'); }); // Client example const results = []; const lookups = [ { type: 'A', name: 'google.com' }, { type: 'AAAA', name: 'google.com' } ]; for (const lookup of lookups) { doh.query({ url: 'https://dns.google.com:443/experimental' }, [lookup], (err, res) => { if (err) throw err; results.push(res.answers); if (results.length === lookups.length) { console.log(JSON.stringify(results, null, 2)); } }); }
Debug
Known issues
gotchaClient query URL must be full HTTPS URL; path '/experimental' is specific to Google DNS.
fix
Use URL like 'https://dns.google.com:443/experimental' or check provider's endpoint.
affects: >=0.0.0
gotchaServer middleware does not validate HTTPS; you must wrap with https.createServer or use reverse proxy.
fix
Use https.createServer with valid cert and key, or terminate SSL upstream.
affects: >=0.0.0
gotchadoh() returns a single request handler; cannot be used as Express middleware directly (expects (req, res)).
fix
Use doh() directly with http.createServer or adapt for Express via (req, res) signature.
affects: >=0.0.0
deprecatedPackage is early WIP (version 0.2.0) with no recent updates. Not recommended for production use.
fix
Consider mature alternatives like node-doh or dns-over-https.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: doh is not a function
ESM import of CJS module without default handling.
fix
Use const doh = require('dns-over-http') or const { default: doh } = await import('dns-over-http').
Error: getaddrinfo ENOTFOUND
Missing or invalid DNS server address in options.servers.
fix
Provide valid IP addresses like '8.8.8.8' in servers array.
TypeError: Cannot read properties of undefined (reading 'answers')
Response callback may receive null or undefined for failed queries.
fix
Check err first; if no error, ensure res has answers property: if (res && res.answers).
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
dns-packetrequiredUsed for encoding and decoding DNS wire format packets.
Agent activity
5 hits · last 30 days
node
4
OpenAI (training)
1
Resources
dns-over-http — npm install dns-over-http · libregistry