Node

A node represents a collection of services that are loaded together. For more information about services, please see the Services Documentation.

API Documentation

  • start() - Will start the node's services in the correct order based on the dependencies of a service.
  • stop() - Will stop the node's services.
  • openBus() - Will create a new event bus to subscribe to events.
  • getAllAPIMethods() - Returns information about all of the API methods from the services.
  • getAllPublishEvents() - Returns information about publish events.
  • getServiceOrder() - Returns an array of service modules.
  • services.<service-name>.<method> - Additional API methods exposed by each service. The services for the node are defined when the node instance is constructed.

Example Usage


var index = require('bitcore-node');
var Bitcoin = index.services.Bitcoin;
var Node = index.Node;

var configuration = {
  datadir: '/home/user/.bitcoin',
  network: 'testnet',
  services: [
    {
      name: 'bitcoind',
      module: Bitcoin,
      config: {}
    }
  ]
};

var node = new Node(configuration);

node.start(function() {
  //start the node so the node.on('ready') is actually called. 
});

node.on('ready', function() {
  console.log('Bitcoin Node Ready');
});

node.on('error', function(err) {
  console.error(err);
});

// shutdown the node
node.stop(function() {
  // the shutdown is complete
});

Node(config)

A node is a hub of services, and will manage starting and stopping the services in the correct order based the the dependency chain. The node also holds common configuration properties that can be shared across services, such as network settings.

The array of services should have the format:

{
  name: 'bitcoind',
  config: {}, // options to pass into constructor
  module: ServiceConstructor
}

Kind: global function

Param Type Description
config Object The configuration of the node
config.formatLogs Array Option to disable formatting of logs
config.services Array The array of services
config.port Number The HTTP port for services
config.https Boolean Enable https
config.httpsOptions Object Options for https
config.httpsOptions.key String Path to key file
config.httpsOptions.cert String Path to cert file

node._setNetwork(config)

Will set the this.network based on a network string.

Kind: instance method of Node

Param Type Description
config Object
config.network String Possible options "testnet", "regtest" or "livenet"

node.openBus() ⇒ Bus

Will instantiate a new Bus for this node.

Kind: instance method of Node

node.getAllAPIMethods() ⇒ Array

Will get an array of API method descriptions from all of the available services.

Kind: instance method of Node

node.getAllPublishEvents() ⇒ Array

Will get an array of events from all of the available services.

Kind: instance method of Node

node.getServiceOrder() ⇒ Array

Will organize services into the order that they should be started based on the service's dependencies.

Kind: instance method of Node

node.start(callback)

Will start all running services in the order based on the dependency chain.

Kind: instance method of Node

Param Type Description
callback function Called when all services are started

node.stop(callback)

Will stop all running services in the reverse order that they were initially started.

Kind: instance method of Node

Param Type Description
callback function Called when all services are stopped