Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including nbonjour2 with all npm packages installed. Try it out:

var nbonjour2 = require("nbonjour2")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

nbonjour2 v3.7.0

A Bonjour/Zeroconf implementation in pure JavaScript node 6 compatible


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

Build status


npm install bonjour


const bonjour = require('nbonjour').create();

// 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);



const bonjour = require('nbonjour').create([options])

The options are optional and will be used when initializing the underlying multicast-dns server. For details see the multicast-dns documentation.


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.


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


Destroy the mdns instance. Closes the udp socket.


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)
  • types(type string | array of strings | array of {type: subtypes})
  • protocol (string) - defaults to tcp
  • txt (object) - passed into dns-txt module 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.

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


Start looking for matching services.


Stop looking for matching services.


Broadcast the query again.


Event: up

Emitted when the service is up.

Event: error

Emitted if an error occurrs while publishing the service.


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


Publish the service.

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


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


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


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

The hostname or ip address where the service resides.


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


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.


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


A boolean indicating if the service is currently published.



RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free