# dns-graceful-stack-switch

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

Latest version **0.1.1** (published 2015-11-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install dns-graceful-stack-switch
pnpm add dns-graceful-stack-switch
yarn add dns-graceful-stack-switch
bun add dns-graceful-stack-switch
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2015-11-05 |
| First published | 2013-08-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.6 <0.12 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 6 |
| Author | Vsevolod Strukchinsky |
| Maintainers | floatdrop |
| Keywords | dns, IPv6, IPv4, stack, ENETUNREACH |

## Links

- npm: https://www.npmjs.com/package/dns-graceful-stack-switch
- Repository: https://github.com/floatdrop/dns-graceful-stack-switch
- Issues: https://github.com/floatdrop/dns-graceful-stack-switch/issues
- npm.io page: https://npm.io/package/dns-graceful-stack-switch

## Alternatives

- [gamedig](https://npm.io/package/gamedig.md) — 29.3K weekly downloads
- [join-monster](https://npm.io/package/join-monster.md) — 12.8K weekly downloads
- [masked](https://npm.io/package/masked.md) — 5.5K weekly downloads
- [@comunica/actor-query-process-explain-logical](https://npm.io/package/@comunica/actor-query-process-explain-logical.md) — 4.7K weekly downloads
- [@veracity/vui](https://npm.io/package/@veracity/vui.md) — 4.6K weekly downloads

## Recent versions

- 0.1.1 (latest) — 2015-11-05
- 0.1.0 — 2015-05-25
- 0.0.7 — 2013-08-29
- 0.0.6 — 2013-08-29

## README

dns-graceful-stack-switch 
========

[![Build Status](https://travis-ci.org/floatdrop/dns-graceful-stack-switch.png?branch=master)](https://travis-ci.org/floatdrop/dns-graceful-stack-switch) [![NPM version](https://badge.fury.io/js/dns-graceful-stack-switch.png)](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

---
_Source: https://npm.io/package/dns-graceful-stack-switch · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
