https://github.com/sagi/dns-over-https-node
RFC-8484 Compliant DNS-over-HTTPS API for Node
https://github.com/sagi/dns-over-https-node
dns dns-over-https doh
Last synced: about 1 year ago
JSON representation
RFC-8484 Compliant DNS-over-HTTPS API for Node
- Host: GitHub
- URL: https://github.com/sagi/dns-over-https-node
- Owner: sagi
- License: mit
- Created: 2018-11-20T12:41:43.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-03-04T04:10:26.000Z (about 3 years ago)
- Last Synced: 2025-04-08T16:38:26.055Z (about 1 year ago)
- Topics: dns, dns-over-https, doh
- Language: JavaScript
- Homepage:
- Size: 1.22 MB
- Stars: 10
- Watchers: 3
- Forks: 2
- Open Issues: 8
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DNS-over-HTTPS API for Node.js
[`@sagi.io/dns-over-https`](https://www.npmjs.com/package/@sagi.io/dns-over-https) is an RFC-8484 compliant Node.js [DNS over HTTPS](https://en.wikipedia.org/wiki/DNS_over_HTTPS) API.
[](https://circleci.com/gh/sagi/dns-over-https-node)
[](https://coveralls.io/github/sagi/dns-over-https-node?branch=master)
[](http://opensource.org/licenses/MIT)
[](http://npm.im/@sagi.io/dns-over-https)
## Installation
~~~
$ npm install --save @sagi.io/dns-over-https
~~~
## API
We import as follows:
~~~js
const doh = require('@sagi.io/dns-over-https')
~~~
#### doh.query(...)
~~~js
doh.query = ({
name,
method = 'POST',
hostname = 'cloudflare-dns.com',
path = '/dns-query',
port = 443,
userAgent = '@sagi.io/dns-over-https',
type = 'A',
klass = 'IN',
useHttps = true,
})
~~~
A `name` is mandatory. You can set your own `method`, `hostname`, `path`, `port`, `userAgent`, `type`, `klass` and `useHttps`.
A `Promise` that resolves to a `DNS` response object is returned.
For instance,
```js
const doh = require('@sagi.io/dns-over-https')
(async () => {
const dnsResponse = await doh.query({name: 'sagi.io'})
})()
```
Results in:
```
{
"id": 0,
"type": "response",
"flags": 384,
"flag_qr": true,
"opcode": "QUERY",
"flag_aa": false,
"flag_tc": false,
"flag_rd": true,
"flag_ra": true,
"flag_z": false,
"flag_ad": false,
"flag_cd": false,
"rcode": "NOERROR",
"questions": [
{
"name": "sagi.io",
"type": "A",
"class": "IN"
}
],
"answers": [
{
"name": "sagi.io",
"type": "A",
"ttl": 300,
"class": "IN",
"flush": false,
"data": "151.101.1.195"
},
{
"name": "sagi.io",
"type": "A",
"ttl": 300,
"class": "IN",
"flush": false,
"data": "151.101.65.195"
}
],
"authorities": [],
"additionals": []
}
```
More usage examples can be found in [`example`](https://github.com/sagi/dns-over-https-node/blob/master/example/index.js).
## License
MIT