# bonjour

> A Bonjour/Zeroconf implementation in pure JavaScript

Latest version **3.5.1** (published 2026-02-14) · MIT license · 0 weekly downloads

## Install

```sh
npm install bonjour
pnpm add bonjour
yarn add bonjour
bun add bonjour
```

## Health

**Score 53/100 (C)** — status: stable.

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

Warnings: low downloads; no esm support.

## Facts

| | |
|---|---|
| Version | 3.5.1 |
| Published | 2026-02-14 |
| First published | 2013-10-03 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/bonjour) |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 31.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 652 |
| Author | Thomas Watson Steen |
| Maintainers | watson |
| Keywords | bonjour, zeroconf, zero, configuration, mdns, dns, service, discovery, multicast, broadcast, dns-sd |

## Links

- npm: https://www.npmjs.com/package/bonjour
- Repository: https://github.com/watson/bonjour
- Issues: https://github.com/watson/bonjour/issues
- npm.io page: https://npm.io/package/bonjour

## Dependencies (6)

- [dns-txt](https://npm.io/package/dns-txt.md) ^2.0.2
- [dns-equal](https://npm.io/package/dns-equal.md) ^1.0.0
- [deep-equal](https://npm.io/package/deep-equal.md) ^1.0.1
- [array-flatten](https://npm.io/package/array-flatten.md) ^2.1.0
- [multicast-dns](https://npm.io/package/multicast-dns.md) ^7.2.3
- [multicast-dns-service-types](https://npm.io/package/multicast-dns-service-types.md) ^1.1.0

## Alternatives

- [jsforce](https://npm.io/package/jsforce.md) — 851.2K weekly downloads
- [react-native-qrcode-svg](https://npm.io/package/react-native-qrcode-svg.md) — 693.5K weekly downloads
- [@salesforce/plugin-data](https://npm.io/package/@salesforce/plugin-data.md) — 394.9K weekly downloads
- [@backstage/plugin-search-common](https://npm.io/package/@backstage/plugin-search-common.md) — 308.5K weekly downloads
- [@chain-registry/types](https://npm.io/package/@chain-registry/types.md) — 38.4K weekly downloads

## Recent versions

- 3.5.1 (latest) — 2026-02-14
- 3.5.0 — 2016-05-07
- 3.4.0 — 2016-05-06
- 3.3.1 — 2016-04-30
- 3.3.0 — 2016-04-20
- 3.2.2 — 2016-02-29
- 3.2.1 — 2016-02-29
- 3.2.0 — 2016-01-23
- 3.1.0 — 2016-01-18
- 3.0.1 — 2016-01-10
- 3.0.0 — 2015-12-29
- 2.0.0 — 2015-12-14
- 1.0.0 — 2013-10-03

## README

# bonjour

A Bonjour/Zeroconf protocol implementation in pure JavaScript. Publish
services on the local network or discover existing services using
multicast DNS.

[![CI](https://github.com/watson/bonjour/actions/workflows/ci.yml/badge.svg)](https://github.com/watson/bonjour/actions/workflows/ci.yml)
[![js-standard-style](https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat)](https://github.com/feross/standard)

## Installation

```
npm install bonjour
```

## Usage

```js
var bonjour = require('bonjour')()

// advertise an HTTP server on port 3000
bonjour.publish({ name: 'My Web Server', type: 'http', port: 3000 })

// browse for all http services
bonjour.find({ type: 'http' }, function (service) {
  console.log('Found an HTTP server:', service)
})
```

## API

### Initializing

```js
var bonjour = require('bonjour')([options])
```

The `options` are optional and will be used when initializing the
underlying multicast-dns server. For details see [the multicast-dns
documentation](https://github.com/mafintosh/multicast-dns#mdns--multicastdnsoptions).

### Publishing

#### `var service = bonjour.publish(options)`

Publishes a new service.

Options are:

- `name` (string)
- `host` (string, optional) - defaults to local hostname
- `port` (number)
- `type` (string)
- `subtypes` (array of strings, optional)
- `protocol` (string, optional) - `udp` or `tcp` (default)
- `txt` (object, optional) - a key/value object to broadcast as the TXT
  record

IANA maintains a [list of official service types and port
numbers](http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml).

#### `bonjour.unpublishAll([callback])`

Unpublish all services. The optional `callback` will be called when the
services have been unpublished.

#### `bonjour.destroy()`

Destroy the mdns instance. Closes the udp socket.

### Browser

#### `var browser = bonjour.find(options[, onup])`

Listen for services advertised on the network. An optional callback can
be provided as the 2nd argument and will be added as an event listener
for the `up` event.

Options (all optional):

- `type` (string)
- `subtypes` (array of strings)
- `protocol` (string) - defaults to `tcp`
- `txt` (object) - passed into [dns-txt
  module](https://github.com/watson/dns-txt) contructor. Set to `{
  binary: true }` if you want to keep the TXT records in binary

#### `var browser = bonjour.findOne(options[, callback])`

Listen for and call the `callback` with the first instance of a service
matching the `options`. If no `callback` is given, it's expected that
you listen for the `up` event. The returned `browser` will automatically
stop it self after the first matching service.

Options are the same as given in the `browser.find` function.

#### `Event: up`

Emitted every time a new service is found that matches the browser.

#### `Event: down`

Emitted every time an existing service emmits a goodbye message.

#### `browser.services`

An array of services known by the browser to be online.

#### `browser.start()`

Start looking for matching services.

#### `browser.stop()`

Stop looking for matching services.

#### `browser.update()`

Broadcast the query again.

### Service

#### `Event: up`

Emitted when the service is up.

#### `Event: error`

Emitted if an error occurrs while publishing the service.

#### `service.stop([callback])`

Unpublish the service. The optional `callback` will be called when the
service have been unpublished.

#### `service.start()`

Publish the service.

#### `service.name`

The name of the service, e.g. `Apple TV`.

#### `service.type`

The type of the service, e.g. `http`.

#### `service.subtypes`

An array of subtypes. Note that this property might be `null`.

#### `service.protocol`

The protocol used by the service, e.g. `tcp`.

#### `service.host`

The hostname or ip address where the service resides.

#### `service.port`

The port on which the service listens, e.g. `5000`.

#### `service.fqdn`

The fully qualified domain name of the service. E.g. if given the name
`Foo Bar`, the type `http` and the protocol `tcp`, the `service.fqdn`
property will be `Foo Bar._http._tcp.local`.

#### `service.txt`

The TXT record advertised by the service (a key/value object). Note that
this property might be `null`.

#### `service.published`

A boolean indicating if the service is currently published.

## License

MIT

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