https://github.com/floatdrop/dns-graceful-stack-switch
Monkey patch DNS lookup method for node.js.
https://github.com/floatdrop/dns-graceful-stack-switch
Last synced: about 1 year ago
JSON representation
Monkey patch DNS lookup method for node.js.
- Host: GitHub
- URL: https://github.com/floatdrop/dns-graceful-stack-switch
- Owner: floatdrop
- License: mit
- Created: 2013-08-19T12:22:40.000Z (over 12 years ago)
- Default Branch: master
- Last Pushed: 2015-11-05T07:49:28.000Z (over 10 years ago)
- Last Synced: 2025-03-14T01:31:43.511Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 477 KB
- Stars: 6
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
dns-graceful-stack-switch
========
[](https://travis-ci.org/floatdrop/dns-graceful-stack-switch) [](http://badge.fury.io/js/dns-graceful-stack-switch)
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```](http://nodejs.org/docs/v0.8.25/api/dns.html#dns_dns_resolve6_domain_callback) and get valid IPv6 addresses) - monkey patched lookup method was written.
### How?
```javascript
// 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](https://github.com/joyent/node/commit/edd2fcccf022c7014b374674012283422faa1bed)" 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