npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

doh-query

v0.6.4

Published

Node & Browser tested, Non-JSON DNS over HTTPS fetching with minimal dependencies.

Downloads

33

Readme

doh-query

Node & Browser tested, Non-JSON DNS over HTTPS fetching with minimal dependencies.

DNS over HTTPS (DoH) is protocol designed for performing remote Domain Name System resolution over HTTPS. Requests are made of HTTP to increase user security and privacy. See DNS over HTTPS for more information.

This package provides simple function to make DoH queries both in node and the browser.

Important Note before getting started

By default doh-query uses well-known public dns-over-https servers to execute queries! These servers come with caveats, please look at ./endpoints.md for more information.

JavaScript API

const { query, endpoints } = require('doh-query')
const { cloudflare, google, opendns } = endpoints
try {
  const { answers } = await query({
    questions: [
      {type: 'A', name: 'google.com'},
      {type: 'A', name: 'twitter.com'}
    ]
  }, {
    /* Options (optional) */
    endpoints: [cloudflare, google, opendns], // (optional) all known working unfiltered endpoints
    retry: 3, // (optional) retries if a given endpoint fails; -1 = infinite retries; 0 = no retry
    timeout: 4000, // (optional, default=30000) timeout for single requests
    signal, // (optional) an AbortSignal to abort the request
  })
} catch (error) {
  switch (error.code) {
    case 'HTTP_STATUS': // request failed, http status error
    case 'RESPONSE_ERR': // request failed, invalid response
    case 'ABORT_ERR': // request aborted
    default: // Unexpected error
  }
}

CLI

You can install doh-query as a command-line tool using npm i doh-query -g or by running npx doh-query.

$ doh-query <options> <input>

Execute a dns query over https.

Examples:

  $ doh-query --json -e google \
      '{ "questions": [{ "type": "A", "name": "google.com" }] }'

  $ echo '{ "questions": [{ "type": "A", "name": "google.com" }] }' \
      | doh-query --stdin --endpoint cloudflare

--help, -h ....... Show this help
--version, -v .... Show the version
--json ........... --type=json
--base64 ......... --type=base64
--binary ......... --type=binary
--type ........... Input type. Options: json, base64, binary; Default: json
--out ............ Output type. Defaults to the input --type.
--stdin .......... Get <input> from stdin instead of cli arguments
--endpoint, -e ... Use a specific endpoint. Can be either the name of a known
    endpoint, a json object or an url. By default uses one of the known endpoints.
    If multiple are provided, one at random will be used.
--endpoints ...... Lists all known endpoints as json.
--retry .......... Number of retries to do in case a request fails, default: 3
--timeout ........ Timeout for the request in milliseconds, default: 30000

Endpoints

For an endpoint to work, it needs to satisfy this interface:

interface Endpoint {
  /* Domain name, required! */
  host: string
  /* Path, prefixed with /, defaults to /dns-query */
  path?: string
  /* https port, defaults to 443 */
  port?: number
  /* true, if endpoint logs requests, defaults to false */
  log?: boolean
  /* true, if endpoint support CORS headers, defaults to false */
  cors?: boolean
  /* true, if endpoint filters/redirects DNS packets, defaults to false */
  filter?: boolean
  /* link to documentation, if available */
  docs?: string
  /* Known geographical location */
  location?: string
  /* Method to request dns, defaults to GET */
  method?: 'post' | 'Post' | 'POST' | 'get' | 'Get' | 'GET'
  /* DEBUG ONLY! false to use http to connect instead of https, defaults to true */
  https?: boolean
}

Instead of passing an object you can also pass an endpoint matching a url, with an amendmend as to whether its a POST or GET endpoint.

Examples:

foo.com{ host: 'foo.com' }

http://bar.com:81/query [post]{ host: 'bar.com', path: '/query', port: 81, method: 'post', https: false }

Note: If no path is given, such as foo.com, the path will be assumed as /dns-query, but if a path is given such as foo.com/ it will assume that path /!

See Also

License

MIT