# clever-discovery

> Node client library for service discovery

Latest version **1.2.3** (published 2025-01-02) · ISC license · 0 weekly downloads

## Install

```sh
npm install clever-discovery
pnpm add clever-discovery
yarn add clever-discovery
bun add clever-discovery
```

## Health

**Score 45/100 (D)** — status: stable.

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

Warnings: low downloads; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 1.2.3 |
| Published | 2025-01-02 |
| First published | 2016-11-17 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 16.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Clever |
| Maintainers | cleverdrone, clever |

## Links

- npm: https://www.npmjs.com/package/clever-discovery
- Repository: https://github.com/Clever/discovery-node
- Issues: https://github.com/Clever/discovery-node/issues
- npm.io page: https://npm.io/package/clever-discovery

## Recent versions

- 1.2.3 (latest) — 2025-01-02
- 1.2.2 — 2024-11-13
- 1.2.1 — 2024-09-11
- 1.2.0 — 2024-09-11
- 1.1.0 — 2024-09-04
- 1.0.0 — 2024-09-03
- 0.0.9 — 2020-10-15
- 0.0.8 — 2016-11-17

## README

# discovery-node

This library programmatically finds endpoints for dependencies. Similar to [discovery-go](https://github.com/Clever/discovery-go) and [discovery-python](https://github.com/Clever/discovery-python).

See [Service Discovery](https://clever.atlassian.net/wiki/spaces/ENG/pages/116686857/Discovery) for more details.

## API

- disc = **discovery**(\<service\>, \<interface\>)
  - disc.**proto**() - returns the service protocol
  - disc.**host**() - returns the hostname or ip
  - disc.**port**() - returns the port
  - disc.**host_port**() - returns (\<host\>:\<port\>)
  - disc.**proto_host**() - returns (\<proto\>://\<host\>)
  - disc.**url**() - returns the url (\<proto\>://\<host\>:\<port\>)

- external_url(\<url\>) - returns the external url to use

### Install and import

```bash
npm install --save clever-discovery
```

```node
import { discovery, external_url } from "clever-discovery"
```

### Examples

```node
disc_gearman = discovery("gearman-admin", "http")
try gearman_url = disc_gearman.url() catch err then cb(err)

disc_systemic = discovery("systemic", "thrift")
try systemic_host = disc_systemic.host() catch err then cb(err)
try systemic_port = disc_systemic.port() catch err then cb(err)

try clever_com_url = external_url("clever.com") catch err then cb(err)
```

To see what interfaces a Clever service exposes, check its launch yaml. You should see one or more exposes listed, and the `name` of the expose is used as the `interface` value in the discovery client.

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