/node-mdns-js

Pure JavaScript/NodeJS mDNS discovery implementation.

Primary LanguageJavaScriptApache License 2.0Apache-2.0

mDNS-js

Forked from kmpm/node-mdns-js

Pure JavaScript/NodeJS mDNS discovery implementation. This implementation mimics the node-mdns behavior, works under linux at least and is compatible with avahi. If another daemon like avahi or dns-sd is running, the port sharing feature must be available on your system.

The starting inspiration came from https://github.com/GoogleChrome/chrome-app-samples/tree/master/mdns-browser but adapted for node. It's not much left of that now though.

Examples

var mdns = require('mdns-js');

var browser = mdns.createBrowser(mdns.tcp('http'));

browser.on('ready', function () {
    browser.discover(); 
});


browser.on('serviceUp', function (service) {
  console.log('service up: ', service.name, service.address);
});

browser.on('serviceDown', function (service) {
  console.log('>>>> service down: ', service.name, service.address);
});
var mdns = require('mdns-js');

var serviceName = 'hello_from_' + require('os').hostname().split('.').shift();
var txtRecord = {
    txtvers:'1',
    port:5876,
    seg:1
};

var service = mdns.createAdvertisement(mdns.tcp('http'), 5876, {
  name:serviceName,
  txtRecord:txtRecord});

service.start();

Debugging

This library is using the debug module from TJ Holowaychuk and can be used like this.

DEBUG=mdns:* node examples/simple.js

This will spit out LOTS of information that might be useful. If you have some issues with something where you might want to communicate the contents of a packet (ie create an issue on github) you could limit the debug information to just that.

DEBUG=mdns:browser:packet node examples/simple.js

License

Apache 2.0. See LICENSE file.

References