@dnslink/js
The reference implementation for DNSLink resolver in JavaScript. Tested in Node.js and in the Browser.
Usage
You can use dnslink
both as a CLI tool or a library.
JavaScript API
Getting started with DNSLink resolution in a jiffy:
import { resolve, DNSRcodeError } from '@dnslink/js'
let result
try {
result = await resolve('dnslink.dev/abcd?foo=bar', {
endpoints: ['dns.google'],
signal,
timeout: 1000,
retries: 3
})
} catch (err) {
if (err instanceof DNSRcodeError) {
err.rcode
err.error
err.code
err.domain
if (err.rcode === 3) {
}
} else {
}
}
const { links, log, txtEntries } = result
links.ipfs === [{ identifier: 'QmTg....yomU', ttl: 60 }]
Array.isArray(log)
txtEntries === [{ value: '/ipfs/QmTg....yomU', ttl: 60 }]
Endpoints
You need to specify endpoints to be used with the API. You can specify them the same way as you would in dns-query
.
Possible log statements
The statements contained in the log
are all objects. They may be helpful to figure out why dnslink
is not behaving like you expect. Every statement contains the .code
property that holds the .code
property to understand what happened.
Depending on the warnings code the errors may have additional .entry
property that holds
the problematic TXT entry. A .reason
property may contain an additional reason for that error to occur.
.code | Meaning | Additional properties |
---|
FALLBACK | No _dnslink. prefixed domain was found. Falling back to the regular domain. | |
INVALID_ENTRY | A TXT entry with dnslink= prefix has formatting errors. | .entry , .reason |
Command Line
To use dnslink
in the command line you will need Node.js installed.
Install it permanently using npm i -g @dnslink/js
or run in on-the-fly
using npx @dnslink/js
.
You can get detailed help for the app by passing a --help
option at the end:
$ npx @dnslink/js --help
License
Published under dual-license: MIT OR Apache-2.0