{"id":15337,"library":"hbo-dnsd","title":"DNS Encoder, Decoder, and Server","description":"hbo-dnsd (also known as dnsd) is a Node.js package providing functionalities for encoding and decoding DNS messages, as well as an API to run custom authoritative DNS servers. Currently at version 0.9.8, its development appears to have ceased around 2012, judging by the provided examples and the specified Node.js engine compatibility (>= 0.8). The package differentiates itself by offering direct programmatic control over DNS message structures as JavaScript objects, allowing developers to implement highly customized DNS resolution logic. It enables the creation of dynamic DNS responses based on request parameters, unlike static DNS server configurations. Due to its age, it relies solely on CommonJS modules and is not actively maintained, making it potentially incompatible with modern Node.js versions or ESM-first projects.","status":"abandoned","version":"0.9.8","language":"javascript","source_language":"en","source_url":"https://github.com/hbouvier/dnsd","tags":["javascript","dns","bind","dnsd","iris"],"install":[{"cmd":"npm install hbo-dnsd","lang":"bash","label":"npm"},{"cmd":"yarn add hbo-dnsd","lang":"bash","label":"yarn"},{"cmd":"pnpm add hbo-dnsd","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is CommonJS-only and does not provide an ESM export. Direct `import` statements will fail.","wrong":"import dnsd from 'dnsd'","symbol":"dnsd","correct":"const dnsd = require('dnsd')"},{"note":"`createServer` is a method on the `dnsd` object, not a named export. The package is CJS-only.","wrong":"import { createServer } from 'dnsd'","symbol":"createServer","correct":"const server = dnsd.createServer(...)"}],"quickstart":{"code":"const dnsd = require('dnsd')\n\nconst server = dnsd.createServer(handler)\nserver.zone('example.com', 'ns1.example.com', 'us@example.com', 'now', '2h', '30m', '2w', '10m')\n      .listen(5353, '127.0.0.1')\nconsole.log('Server running at 127.0.0.1:5353')\n\nfunction handler(req, res) {\n  console.log('%s:%s/%s %j', req.connection.remoteAddress, req.connection.remotePort, req.connection.type, req)\n\n  const question = res.question[0]\n    , hostname = question.name\n    , length = hostname.length\n    , ttl = Math.floor(Math.random() * 3600)\n\n  if(question.type == 'A') {\n    res.answer.push({name:hostname, type:'A', data:\"1.1.1.\"+length, 'ttl':ttl})\n    res.answer.push({name:hostname, type:'A', data:\"2.2.2.\"+length, 'ttl':ttl})\n  }\n  res.end()\n}\n\n// To test, run this script and then in your terminal:\n// $ dig @localhost -p 5353 example.com soa\n// $ dig @localhost -p 5353 example.com a","lang":"javascript","description":"Demonstrates creating a dynamic DNS server that responds to A and SOA queries with custom logic, including logging requests and setting dynamic TTLs."},"warnings":[{"fix":"This package is fundamentally incompatible with modern Node.js. Consider using a more actively maintained DNS library like 'dns-packet' for encoding/decoding or 'dnscat2' for server functionality if a custom DNS server is required. There is no direct fix to make this package work reliably on recent Node.js versions.","message":"Outdated Node.js compatibility: The package specifies compatibility with Node.js >= 0.8. Running it on modern Node.js versions (e.g., Node.js 16, 18, 20+) is highly likely to lead to unexpected behavior, runtime errors, or security vulnerabilities due to significant API changes and deprecations in the Node.js core over the last decade.","severity":"breaking","affected_versions":">=0.9.8"},{"fix":"Ensure the file importing `hbo-dnsd` is treated as CommonJS (e.g., use `.cjs` file extension, or remove `\"type\": \"module\"` from `package.json`). If using ESM, a dynamic `import('dnsd')` might technically work in some contexts, but this package's synchronous nature makes it less suitable for such use.","message":"CommonJS-only Module: `hbo-dnsd` is written exclusively in CommonJS (`require()`) and does not provide an ES Module (ESM) export. Developers in modern Node.js projects configured for ESM (`\"type\": \"module\"` in `package.json` or `.mjs` files) will encounter issues.","severity":"gotcha","affected_versions":">=0.9.8"},{"fix":"Do not use this package in production environments or for security-sensitive applications. Seek actively maintained alternatives that adhere to modern security practices and are regularly updated.","message":"Lack of Maintenance & Security: The package has not been updated since 2014 and is considered abandoned. This implies a critical lack of security patches for potential DNS-related vulnerabilities (e.g., DNS amplification, cache poisoning) or compatibility fixes for evolving network standards and operating system changes.","severity":"breaking","affected_versions":">=0.9.8"},{"fix":"If deploying a DNS server on port 53, configure your system to allow the Node.js process to bind to privileged ports (e.g., using `setcap` on Linux), or use a port forwarding/redirection mechanism (e.g., `iptables`). Running the entire Node.js application as root is generally discouraged for security reasons.","message":"Port 53 requires elevated privileges: Running a DNS server on the standard UDP port 53 typically requires root/administrator privileges on most operating systems. The examples provided use port 5353, which is unprivileged, but for an actual public DNS service, port 53 is necessary.","severity":"gotcha","affected_versions":">=0.9.8"},{"fix":"Developers must either write their own declaration files (`declare module 'dnsd';` for basic usage, or more detailed interfaces for `req`, `res`, and server methods) or disable type checking for imports from this module.","message":"No TypeScript definitions: The package does not ship with TypeScript type definitions (`.d.ts` files). This means users in TypeScript projects will lack type safety and autocompletion, potentially leading to runtime errors that would otherwise be caught at compile time.","severity":"gotcha","affected_versions":">=0.9.8"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Ensure the file where `require('dnsd')` is used is treated as a CommonJS module. This can involve changing the file extension to `.cjs` or ensuring `\"type\": \"commonjs\"` is set in the nearest `package.json` for that file's scope.","cause":"Attempting to use `require('dnsd')` in an ES Module context (e.g., in a `.mjs` file or a project with `\"type\": \"module\"` in `package.json`).","error":"ReferenceError: require is not defined"},{"fix":"Run the Node.js process with `sudo` (not recommended for production due to security implications) or configure system capabilities to allow non-root processes to bind to privileged ports. Alternatively, use a higher, unprivileged port (e.g., 5353) and configure network traffic redirection (e.g., `iptables` on Linux, or similar tools on other OS) from port 53 to the chosen unprivileged port.","cause":"The Node.js process attempted to bind to a privileged network port (like port 53) without sufficient operating system permissions (e.g., not running as root).","error":"Error: listen EACCES: permission denied 0.0.0.0:53"},{"fix":"This issue indicates deep incompatibility. The most effective fix is to migrate to a modern, actively maintained DNS library that supports current Node.js versions, as retrofitting this package for modern Node.js is impractical and risky.","cause":"`hbo-dnsd` was developed for Node.js 0.8, and its internal implementation might rely on Node.js core APIs that have changed, been deprecated, or removed in much newer Node.js versions.","error":"TypeError: Cannot read properties of undefined (reading 'listen') (or similar runtime errors related to Node.js core APIs)"}],"ecosystem":"npm"}