cached-dns
TypeScript icon, indicating that this package has built-in type declarations

0.0.4 • Public • Published

cached-dns

Build Status License Docs

DNS caching implementation for Node.js. Provides same API as dns.lookup

NPM

Install

$ npm install cached-dns 

Usage

The lookup function provided by this library has the same API signature as dns.lookup. It supports all options, although options.verbatim is redundant, since the resolver will resolve ipv4 and ipv6 addresses separately, and join them together inside Node.js.

Additionally, the library exposes a lookupPromise function, which has the same API signature as dns.promises.lookup.

You can either use this manually, by passing the lookup function to functions that support it.

const lookup = require("cached-dns").lookup
http.get({
    hostname: 'google.com', 
    path: '/',
    lookup: lookup
}, (res) => {
    console.log('RESPONSE', res.statusCode)
}).on('error', (err) => {
    console.error('ERROR', err)
})

Alternatively, you can tell the library to overwrite the dns module's lookup function, with this implementation. This makes it easier to patch existing code, but is dangerous.

const cachedDNS = require("cached-dns")
cachedDNS.patchGlobal()

// this will now get cached by default
http.get({
    hostname: 'google.com', 
    path: '/',
}, (res) => {
    console.log('RESPONSE', res.statusCode)
}).on('error', (err) => {
    console.error('ERROR', err)
})

Readme

Keywords

Package Sidebar

Install

npm i cached-dns

Weekly Downloads

9,900

Version

0.0.4

License

MIT

Unpacked Size

40.2 kB

Total Files

11

Last publish

Collaborators

  • jamiees2