JSPM

dns-graceful-stack-switch

0.1.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 2
  • Score
    100M100P100Q51194F
  • License MIT

Graceful stack switching in dns.lookup. This will fix ENETUNREACH in case you have IPv4 disabled on host, but IPv6 available.

Package Exports

  • dns-graceful-stack-switch

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (dns-graceful-stack-switch) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

dns-graceful-stack-switch

Build Status NPM version

Monkey patch DNS lookup method for node.js.

Why?

If you used node.js with disabled IPv4 - you got exception (ENETUNREACH) in most of network operations, but ping6 address working fine.

To fix this error with minimal amount of code (you still can use dns.resolve6 and get valid IPv6 addresses) - monkey patched lookup method was written.

How?

// Monkey patch
require('dns-graceful-stack-switch')(6);
// Remove monkey patch
require('dns-graceful-stack-switch')(null, true);

This module returns function(defaultVersion, remove).

  • defaultVersion - IP stack version that will be used first to lookup address. If it fails - another will be used. Defaults to process.env.NODE_DNS_GRACEFUL_STACK_SWITCH_DEFAULT and after that to 4.
  • remove - remove monkeypatch. Defaults to false.

After executing dns.lookup will be loaded with require and lookup method will be replaced.

Node.JS way

This bug was "patched" in Node.js, but magic option in net.connect (which gives you ability to write right http.Agent) released only in Node.js 0.11.6.

To run the tests:

Unix/Macintosh:

make test