$ cnpm install dnssd-advertise
A well-behaved Bonjour/DNS-SD service advertiser for Node.js, designed for long-running processes.
import { advertise } from 'dnssd-advertise';
const stop = advertise({
name: 'My Service',
type: 'http',
protocol: 'tcp',
port: 3000,
});
process.on('exit', () => {
stop();
});
When a conflict is detected during probing, as per the specification, the name or hostname of your service may be altered:
name conflicts a 4-character hex ID is appended (e.g. My Service (B0A1)hostname conflicts a number is appended to it (e.g. my-hostname-2)When a conflict is detected during announcing, the probing phase restarts with the same conflict resolution.
advertise(options): () => Promise<void>Starts advertising a DNS-SD service on all available network interfaces.
Returns a function that, when called, stops advertising and sends goodbye packets to remove the service from the network. Stopping the advertiser is, while preferred, optional as per the mDNS specification.
| Option | Type | Description |
|---|---|---|
name |
string |
Instance/display name of the service (e.g., "Living Room Speaker") |
type |
string |
Service type without protocol (e.g., "http", "ssh", "airplay") |
protocol |
'tcp' \| 'udp' |
Protocol used by the service |
port |
number |
Port the service is listening on |
hostname |
string |
Hostname to advertise (defaults to system hostname) |
subtypes |
string[] |
Optional list of subtypes |
txt |
Record<string, TxtValue> |
Optional service metadata as key-value pairs |
ttl |
number |
TTL for DNS records in seconds (defaults to 250s) |
Copyright 2013 - present © cnpmjs.org | Home |