# consul-balancer

> consul service discovery and balancing

Latest version **1.0.10** (published 2023-08-29) · ISC license · 0 weekly downloads

## Install

```sh
npm install consul-balancer
pnpm add consul-balancer
yarn add consul-balancer
bun add consul-balancer
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.10 |
| Published | 2023-08-29 |
| First published | 2023-01-08 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 17 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | cynosurech@gmail.com |
| Maintainers | cynosure |
| Keywords | consul, load-balance, service, discovery |

## Links

- npm: https://www.npmjs.com/package/consul-balancer
- Repository: https://github.com/yolopunk/consul-balancer
- Homepage: https://github.com/yolopunk/consul-balancer#readme
- Issues: https://github.com/yolopunk/consul-balancer/issues
- npm.io page: https://npm.io/package/consul-balancer

## Dependencies (6)

- [consul](https://npm.io/package/consul.md) ^1.2.0
- [urllib](https://npm.io/package/urllib.md) ^2.40.0
- [lodash.set](https://npm.io/package/lodash.set.md) ^4.3.2
- [lodash.omit](https://npm.io/package/lodash.omit.md) ^4.5.0
- [lodash.sample](https://npm.io/package/lodash.sample.md) ^4.2.1
- [lodash.defaults](https://npm.io/package/lodash.defaults.md) ^4.2.0

## Recent versions

- 1.0.10 (latest) — 2023-08-29
- 1.0.9 — 2023-08-28
- 1.0.8 — 2023-08-28
- 1.0.7 — 2023-03-07
- 1.0.6 — 2023-01-11
- 1.0.5 — 2023-01-09
- 1.0.4 — 2023-01-08

## README

# consul-balancer

> consul service discovery and balancing

## usage

```bash
npm install consul-balancer
```

```js
import { ConsulBalancer } from "consul-balancer"

const consulBalancer = new ConsulBalancer({
  host: "x.x.x.x",
  port: 8500,
  secure: false,
  discovery: {
    enable: true,
    register: true, // auto register discovery service
    deregister: true, // auto register discovery service after process exited
    serviceName: "consul-balancer",
    servicePort: 8080,
    healthCheckHTTP: "/healthy",
  },
})
```

## API

- `consulBalancer.getConsulInstance()`: get the consul client instance
- `consulBalancer.getPassingServiceByRandom(serviceName)`: get the info of passing service by random
- `consulBalancer.register(options?: RegisterOptions)`: registers the discovery service
- `consulBalancer.deregister(serviceId?: string)`: deregister the discovery service
- `consulBalancer.rest(serviceName, pathName, urlOptions)`: [async function] load balance http utils

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