Aesir NS ยท The DNS client
Bragi NS Client: a faster, safer dns.lookup
Bragi is a drop-in replacement for the dns.lookup of Node.js. It caches addresses exactly as long as their DNS records allow, never touches the libuv thread pool, and can check with DNSSEC that an answer is authentic. Odin uses it for its own outgoing connections.
- Version 2.1.0
- MIT licence
- No dependencies
- Node.js 20
At a glance
| Package | bragi-ns-client |
|---|---|
| Version | 2.1.0 |
| Licence | MIT |
| Dependencies | None |
| Used by | Odin NS Manager |
What it does
dns.lookup runs on the thread pool, which has four threads by default and is shared with files and crypto; it caches nothing and can not tell whether an answer is authentic. Bragi fixes all three.
No thread pool
Uses
dns.resolve4anddns.resolve6instead ofgetaddrinfo, so slow DNS answers do not block files and crypto.TTL aware
Addresses are cached exactly as long as the DNS record allows.
Round-robin
Every call returns the next address of the host.
One query per host
Parallel lookups of the same host share a single DNS query.
DNSSEC
Optional: the package validates the answers itself up to the built-in root keys, or trusts a validating DNS server you choose.
Zero dependencies
Nothing else to install or to keep up to date.
Get started
Install it, and pass it where a lookup function is accepted.
Install
From npm.
npm install bragi-ns-client
Every request through an agent
Pass lookup to anything that accepts a custom lookup function: http, https, net and most HTTP clients.
const https = require('node:https');
const {lookup} = require('bragi-ns-client');
const agent = new https.Agent({keepAlive: true, lookup});
https.get('https://example.com', {agent}, response => {
// ...
});
With DNSSEC
A forged DNS answer can not redirect the connection.
const https = require('node:https');
const {createLookup, DNSSEC_BOGUS} = require('bragi-ns-client');
const lookup = createLookup({dnssec: 'validate'});
https.get('https://example.com', {lookup}, response => {
// ...
}).on('error', error => {
if (error.code === DNSSEC_BOGUS) {
// The DNS answer was forged or the DNSSEC setup of the domain is broken
}
});
Some local resolvers strip the DNSSEC records; then every answer fails. Name another DNS server with the servers option.
What it needs
| Node.js | 20 or newer |
|---|---|
| Dependencies | None |
| DNSSEC | A correct system clock, and a DNS server that hands over the DNSSEC records |
The other modules
Each module has its own repository and version. A release of Odin pins the versions of the others, and the installer installs exactly those.
-
Odin NS Manager
The service you install. It brings the others together: the DNS server, the management API, the interface and the installers.
-
Njord NS Server
The DNS server engine in pure JavaScript: UDP and TCP, EDNS0, zone transfers and a recursor. It hands you each query as an object to answer.
-
Freya NS API
The management API: zones and records, blocking, monitoring, users and sign-in, export and import, and the HTTPS certificate.