# net-socket-reconnect

> makes net.connect() and net.createConnection() auto reconnect

Latest version **0.0.9** (published 2015-01-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install net-socket-reconnect
pnpm add net-socket-reconnect
yarn add net-socket-reconnect
bun add net-socket-reconnect
```

## 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.0.9 |
| Published | 2015-01-30 |
| First published | 2015-01-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | David Sky |
| Maintainers | david_sky |
| Keywords | socket, reconnect, connect, createConnection, net, auto-reconnect |

## Links

- npm: https://www.npmjs.com/package/net-socket-reconnect
- Repository: https://github.com/davidSky/node-net-socket-reconnect
- Issues: https://github.com/davidSky/node-net-socket-reconnect/issues
- npm.io page: https://npm.io/package/net-socket-reconnect

## Alternatives

- [@opentelemetry/exporter-zipkin](https://npm.io/package/@opentelemetry/exporter-zipkin.md) — 14.8M weekly downloads
- [pusher-js](https://npm.io/package/pusher-js.md) — 2.0M weekly downloads
- [browserify](https://npm.io/package/browserify.md) — 1.7M weekly downloads
- [sqs-consumer](https://npm.io/package/sqs-consumer.md) — 1.7M weekly downloads
- [@sanity/eventsource](https://npm.io/package/@sanity/eventsource.md) — 930.8K weekly downloads

## Recent versions

- 0.0.9 (latest) — 2015-01-30
- 0.0.8 — 2015-01-29
- 0.0.7 — 2015-01-29
- 0.0.6 — 2015-01-29
- 0.0.5 — 2015-01-29
- 0.0.3 — 2015-01-28
- 0.0.2 — 2015-01-07
- 0.0.1 — 2015-01-07

## README

# net-reconnect
Makes net.connect() and net.createConnection() auto reconnect.
## Usage
```js
var reconnect= require('net-socket-reconnect')
var client= reconnect({port: 8080, reconnectInterval: 150}) // no change to original API
```
## Options
* __`reconnectOnError`__ reconnect on 'error', default false
* __`reconnectOnEnd`__ reconnect on 'end', default false
* __`reconnectOnClose`__ reconnect on 'close', default true
* __`reconnectOnTimeout`__ reconnect on 'timeout', default false
* __`reconnectOnCreate`__ reconnect after initial connect failed, default false
* __`reconnectInterval`__ interval between tries, default 300
* __`reconnectTimes`__ max retries, default 50

> __note__: 50 * 300= 15,000. That's 15 seconds of retrying and then giving up with `reconnectFailed` event

## Methods
Except the original events, there's a few new ones:
* __`client.reconnect()`__  ends current connection and reconnects; or simple reconnects if you set all auto reconnect options to false (and decided to deal with it manually)
* __`client.stopReconnect()`__ stops any further reconnect actions
* __`client.startReconnect()`__ restarts reconnect
* __`client.getReconnect()`__ get current reconnect state: true/on, or false/off

## Events
Except the original events, there's a two new ones:
* __`reconnect`__ when successfuly reconnected
* __`reconnectFailed`__ when reconnect reached reconnectTimes 

> __important__: every successful reconnect will also emit __`'connect'`__ event by net.Socket, so plan your client.on('connect', function(){}) callbacks

## Installation
```
npm install net-socket-reconnect
```
---
MIT License

---
_Source: https://npm.io/package/net-socket-reconnect · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
