Simple, robust, BitTorrent DHT implementation

npm install bittorrent-dht
214 downloads in the last day
1 077 downloads in the last week
3 921 downloads in the last month

bittorrent-dht build npm npm downloads gittip

Simple, robust, BitTorrent DHT implementation

Node.js implementation of the BitTorrent DHT protocol. BitTorrent DHT is the main peer discovery layer for BitTorrent, which allows for trackerless torrents. DHTs are awesome!

This module is used by WebTorrent. Works in the browser with browserify and a dgram shim (like chrome-dgram for chrome apps).


npm install bittorrent-dht


npm install magnet-uri
var DHT    = require('bittorrent-dht');
var magnet = require('magnet-uri');

var uri = "magnet:?xt=urn:btih:e3811b9539cacff680e418124272177c47477157&dn=Ubuntu+13.10+Desktop+Live+ISO+amd64";
var parsed = magnet(uri);

var dht = new DHT();

dht.on('peer', function (addr, hash) {
  console.log('Found peer at ' + addr + '!');


var port = 20000;
dht.listen(port, function (port) {
  console.log("Now listening on port " + port);




Associate an infoHash with the DHT object. Can be a String or Buffer.

dht.listen([port], [callback])

Open the socket. If port is undefined, one is picked with portfinder. callback is equivalent to listening event.


Get num peers from the DHT. Defaults to unlimited.



function (addr, infoHash){ ... }

Called when a peer is found. addr is of the form IP_ADDRESS:PORT


function (data, rinfo){ ... }

Called when a message is received. rinfo is an object with properties address, port


function (addr){ ... }

Called when client finds a new DHT node.


function () { ... }


function (err){ ... }


MIT. Copyright (c) Feross Aboukhadijeh.

npm loves you