Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cached-dns

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cached-dns

A library to cache DNS lookups in Node.js

  • 0.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
141
decreased by-37.05%
Maintainers
1
Weekly downloads
 
Created
Source

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)
})

Keywords

FAQs

Package last updated on 26 Jul 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc