Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslnode 18–226 runs
build_error
glibcnode 18–226 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
mdns instance (CommonJS)
✓ const mdns = require('multicast-dns')();
✗ const mdns = require('multicast-dns');
The `multicast-dns` package exports a factory function that must be immediately invoked to create an mDNS instance.
mdns instance (ESM)
✓ import createMdns from 'multicast-dns';
const mdns = createMdns();
✗ import { mdns } from 'multicast-dns';
For ESM, import the default export (the factory function) and then call it to get a new mDNS instance. The package's primary documentation showcases CommonJS usage.
Packet Types (TypeScript)
✓ import type { Packet, Question, Answer } from 'multicast-dns';
✗ import { Packet } from 'multicast-dns';
While the library is JavaScript, TypeScript type definitions are often available via `@types/multicast-dns` for enhanced development experience. Common types include `Packet`, `Question`, and `Answer` for handling mDNS data structures.
This quickstart initializes a `multicast-dns` instance, logs incoming query and response packets, demonstrates how to query for specific records, and how to respond to queries for a known service, then destroys the instance.
import createMdns from 'multicast-dns';
const mdns = createMdns();
mdns.on('response', function(response) {
console.log('Got a mDNS response packet:', JSON.stringify(response, null, 2));
});
mdns.on('query', function(query) {
console.log('Got a mDNS query packet:', JSON.stringify(query, null, 2));
// Example: Respond to a query for 'my-service.local'
if (query.questions[0] && query.questions[0].name === 'my-service.local') {
mdns.respond({
answers: [{
name: 'my-service.local',
type: 'A',
ttl: 120,
data: '127.0.0.1' // Replace with actual IP
}]
});
console.log('Responded to query for my-service.local');
}
});
// Query for an A record for a local hostname (e.g., your-hostname.local)
mdns.query({
questions:[
{
name: 'your-hostname.local',
type: 'A'
},
{
name: 'my-service.local',
type: 'SRV'
}
]
});
console.log('Sent mDNS query for your-hostname.local and my-service.local');
// Destroy the instance after a timeout to prevent resource leaks in short-lived scripts
setTimeout(() => {
mdns.destroy();
console.log('mDNS instance destroyed.');
}, 10000);
Debug
Known issues
gotchaThe `reuseAddr` option for the underlying UDP socket requires Node.js version 0.11.13 or newer. Using it on older versions will result in an error or unexpected behavior.fixEnsure your Node.js runtime is updated to a modern version (LTS recommended) or avoid using the `reuseAddr: true` option.
affects: <0.11.13
gotchaThe mDNS protocol operates over UDP port 5353, which is a well-known port. Firewalls or other services (like Bonjour/Avahi daemons) might block access or already be using this port, leading to `EADDRINUSE` or `EACCES` errors when binding the socket.fixEnsure port 5353 is open in your firewall for UDP traffic, or configure a different `port` option (though this would break standard mDNS discovery). If another service is listening, stop it or configure `multicast-dns` to use a different `interface` if available.
affects: >=1.0.0
gotchaThe README and examples primarily demonstrate CommonJS (`require()`) usage. While modern Node.js supports ESM, careful consideration is needed for `import` statements, especially when the package exports a factory function that needs to be invoked immediately.fixFor ESM, use `import createMdns from 'multicast-dns'; const mdns = createMdns();`. Avoid named imports like `{ mdns }` unless explicitly documented, as the default export is a function. affects: >=6.0.0 (Node.js versions with ESM support)
Errors
Common errors & fixes
Error: bind EADDRINUSE 224.0.0.251:5353
Another process (e.g., a system mDNS responder like Bonjour or Avahi, or another instance of `multicast-dns`) is already listening on the default mDNS port and multicast address.
fixStop the conflicting process, or configure your `multicast-dns` instance to bind to a specific `interface` if available, or a different `port` (which will prevent standard mDNS discovery for that instance).
Error: bind EADDRNOTAVAIL
The specified network `interface` in the options (e.g., `interface: '192.168.0.2'`) does not exist or is not available on the current system.
fixVerify the IP address configured for the `interface` option is correct and corresponds to an active network interface on your machine. Remove the `interface` option to let `multicast-dns` bind to all available interfaces (default behavior).
TypeError: multicastdns is not a function
The imported/required `multicast-dns` module was not invoked as a function to create an instance. For example, `const mdns = require('multicast-dns');` instead of `const mdns = require('multicast-dns')();`.
fixEnsure you are calling the imported module as a function: `const mdns = require('multicast-dns')();` for CommonJS, or `const mdns = createMdns();` after `import createMdns from 'multicast-dns';` for ESM. Audit
Dependencies
No dependency data recorded yet.