Skip to content

Instantly share code, notes, and snippets.

@shime
Last active November 8, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shime/cc4b9d5737b9ada9baf8 to your computer and use it in GitHub Desktop.
Save shime/cc4b9d5737b9ada9baf8 to your computer and use it in GitHub Desktop.
Hello world over bittorrent DHT
node_modules
*.log

Hello world over Bittorrent DHT

git clone git@gist.github.com:8af1e7887515133208af.git hello-world
cd hello-world
npm install 
npm start

var DHT = require('bittorrent-dht')
var dht = new DHT()
var value = new Buffer(11).fill('hello world')
console.log('putting data, please wait...')
dht.on('ready', function () {
dht.put({ v: value }, function (errors, hash) {
console.error('errors=', errors)
console.log('hash=', hash)
console.log('getting data, please wait...')
dht.get(hash, function(errors, res){
console.error('errors=', errors)
console.log(res.v.toString())
})
})
})
{
"name": "bittorrent-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "node hello.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"bittorrent-dht": "^4.0.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment