Skip to content

Instantly share code, notes, and snippets.

@shime shime/.gitignore
Last active Nov 8, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.