Registry / devops / cached-dns

cached-dns

JSON →
library0.0.4jsnpmunverified

A lightweight DNS caching library for Node.js that wraps the built-in dns.lookup and dns.promises.lookup with a TTL-based cache. Current stable version is 0.0.4, released as a single module with TypeScript types. It provides a drop-in replacement for Node.js DNS resolution with configurable cache size and TTL. Key differentiators: same API as Node's dns module, supports callback and promise variants, optional global patching, and no external dependencies. Release cadence is low; package is minimal and focused.

npm install cached-dns
INSTALL
IMPORT
SIG · CACHED-DNS
C
cached-dns
devopsjavascriptv0.0.4
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

lookup
import { lookup } from 'cached-dns'
import lookup from 'cached-dns'
This is a named export, not a default export.
lookupPromise
import { lookupPromise } from 'cached-dns'
Promise-based version of the lookup function.
patchGlobal
import { patchGlobal } from 'cached-dns'
Patches Node's global dns.lookup; use with caution.
CachedDNS Options
import { CacheOptions } from 'cached-dns'
TypeScript type for cache configuration (TTL, max size).

Demonstrates callback lookup, promise lookup, and usage with http.get.

import { lookup, lookupPromise } from 'cached-dns'; import http from 'http'; // Callback style lookup('google.com', { family: 4 }, (err, address, family) => { console.log('IP:', address); }); // Promise style const ip = await lookupPromise('google.com', { family: 4 }); console.log('IP:', ip); // Use custom lookup in http.get http.get({ hostname: 'google.com', path: '/', lookup }, (res) => { console.log('Status:', res.statusCode); });
Debug
Known issues
breakingGlobal patching via patchGlobal() is irreversible and can cause unexpected behavior in tests and production.
fix
Avoid using patchGlobal() for persistent changes; pass lookup function explicitly.
affects: >=0.0.1
deprecatedThe callback API may be deprecated in future versions in favor of async/await.
fix
Use lookupPromise for new projects; callback API is stable but not recommended.
affects: >=0.0.1
gotchaCache is entirely in-memory and does not persist across process restarts; no external cache backend.
fix
Be aware that cache is per-process; consider external caching if persistence is needed.
affects: >=0.0.1
gotchaThe library does not implement standard Node.js DNS error handling (e.g., ENOTFOUND) — errors are direct from dns.lookup.
fix
Wrap calls in try-catch when using promises, or handle errors in callbacks as usual.
affects: >=0.0.1
Errors
Common errors & fixes
Cannot find module 'cached-dns'
Package not installed or not in node_modules.
fix
Run 'npm install cached-dns' in your project root.
lookup is not a function
Wrong import style: trying to use default import instead of named import.
fix
Use `import { lookup } from 'cached-dns'` instead of `import lookup from 'cached-dns'`.
TypeError: Cannot read property 'lookup' of undefined
Assuming cached-dns exports the full dns module object.
fix
Import individual functions: `import { lookup } from 'cached-dns'`.
Upgrade
Version history
0.0.4latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
cached-dns — npm install cached-dns · libregistry