Branch: master
Find file History
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


Gitter chat license

Node Operator for BlockHub

BlockHub Node Operator assists BlockHub clients with the following:

  • Brokering p2p connections between clients. Data is not proxied/passed through the operator.
  • Distributing IPFS downloads.
  • Serving data for clients to hydrate screen information (such as a product page).

Quick Links


Install Node Package Manager (NVM):

curl -o- | bash

Install Node 8.11.1:

nvm install 8.11.1

If you get nvm: command not found, simply close your current terminal, open a new terminal, and try again. Please see the NVM readme if you have any issues.

Run Server

Install the library:

$> yarn add blockhub-node-operator

Run the server:

$> blockhub-node-operator --port 9000 --key nodeOperator

Or, create a custom server:

let BlockHubServer = require('blockhub-node-operator').BlockHubServer
let server = BlockHubServer({ port: 9000, path: '/myapp' })

Connecting to the server from frontend:

    let peer = new Peer('someid', { host: 'localhost', port: 9000, path: '/myapp' })

Using HTTPS: Simply pass in PEM-encoded certificate and key.

let fs = require('fs')
let BlockHubServer = require('peer').BlockHubServer

let server = BlockHubServer({
  port: 9000,
  ssl: {
    key: fs.readFileSync('/path/to/your/ssl/key/here.key'),
    cert: fs.readFileSync('/path/to/your/ssl/certificate/here.crt')

Running BlockHubServer behind a reverse proxy

Make sure to set the proxied option, otherwise IP based limiting will fail. The option is passed verbatim to the expressjs trust proxy setting if it is truthy.

let BlockHubServer = require('blockhub-node-operator').BlockHubServer
let server = BlockHubServer({ port: 9000, path: '/myapp', proxied: true })

Combining with existing express app

let express = require('express')
let app = express()
let ExpressServer = require('blockhub-node-operator').ExpressServer

app.get('/', function(req, res, next) { res.send('Hello world!') })

// =======

let server = app.listen(9000)

let options = {
    debug: true

let expressServer = ExpressServer(server, options)

app.use('/api', expressServer)

// == OR ==

let server = require('http').createServer(app)
let expressServer = ExpressServer(server, options)

app.use('/nodeOperator', expressServer)


// ========


The 'connection' event is emitted when a peer connects to the server.

expressServer.on('connection', function(id) { ... })

The 'disconnect' event is emitted when a peer disconnects from the server or when the peer can no longer be reached.

expressServer.on('disconnect', function(id) { ... })


Discuss Node Operator on our Gitter:

Please post any bugs as a Github issue.