Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
bonjour-service
Advanced tools
The bonjour-service npm package is a Node.js implementation of multicast DNS service discovery, a way of using standard DNS protocols to enable devices on the same local network to discover each other. It allows for the advertisement and discovery of services such as HTTP servers, printers, and other devices or services available on the local network without the need for manual configuration.
Advertise a service
This feature allows you to advertise a service on the local network. In this example, a web server is advertised using the HTTP protocol on port 3000.
const bonjour = require('bonjour-service')();
bonjour.publish({ name: 'My Web Server', type: 'http', port: 3000 });
Discover services
This feature enables the discovery of services advertised on the local network. The example code searches for services of the type 'http' and logs any that are found.
const bonjour = require('bonjour-service')();
bonjour.find({ type: 'http' }, function (service) {
console.log('Found an HTTP server:', service);
});
Unpublish all services
This feature allows for the removal of all advertised services from the network. It's useful for cleanup, especially when shutting down an application that has advertised multiple services.
const bonjour = require('bonjour-service')();
// After services have been published
bonjour.unpublishAll(() => {
console.log('All services have been unpublished.');
});
The mdns package is another Node.js based multicast DNS service discovery library. It provides similar functionalities for advertising and discovering services on the local network. Compared to bonjour-service, mdns might require more configuration and manual handling of network interfaces but offers more detailed control over the mDNS process.
node-ssdp is a simple service discovery protocol implementation for Node.js. It differs from bonjour-service by focusing on SSDP (Simple Service Discovery Protocol) which is commonly used for UPnP (Universal Plug and Play) devices. While it serves a similar purpose in service discovery, its use case is more aligned with UPnP devices rather than the broader mDNS-based discovery that bonjour-service provides.
A Bonjour/Zeroconf protocol implementation in TypeScript. Publish services on the local network or discover existing services using multicast DNS.
This is a rewrite of the project Bonjour (https://github.com/watson/bonjour) into modern TypeScript.
bonjour-service is supported by ON LX Limited. Check out our projects such as Ctrl Suite and Ctrl for iPad.
Add to your project dependencies using Yarn or NPM.
yarn add bonjour-service
npm install bonjour-service
import { Bonjour } from 'bonjour-service'
const instance = new Bonjour()
// advertise an HTTP server on port 3000
instance.publish({ name: 'My Web Server', type: 'http', port: 3000 })
// browse for all http services
instance.find({ type: 'http' }, function (service) {
console.log('Found an HTTP server:', service)
})
var instance = new Bonjour({ options }, errorCallback)
The options
are optional and will be used when initializing the
underlying multicast-dns server. For details see the multicast-dns
documentation.
errorCallback
is an optional callback used to gracefully handle errors that would otherwise
crash the process. While not being strictly required, providing this is highly recommended
var service = bonjour.publish(options)
Publishes a new service.
Options are:
name
(string)host
(string, optional) - defaults to local hostnameport
(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
recorddisableIPv6
(boolean, optional) disble IPv6 addressesIANA maintains a list of official service types and port numbers.
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.
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 contructor. Set to { binary: true }
if you want to keep the TXT records in binaryvar 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.
Event: txt-update
Emitted every time an existing service does a new announcement with an updated TXT record.
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.
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.
MIT
FAQs
A Bonjour/Zeroconf implementation in TypeScript
The npm package bonjour-service receives a total of 9,415,649 weekly downloads. As such, bonjour-service popularity was classified as popular.
We found that bonjour-service demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.