Node.js

Node.js

BitSensor Node.js Plugin

BitSensor Node.js Plugin

Usage

Add bitsensor to your dependencies.

npm install bitsensor-node-js-core npm install bitsensor-node-js-http npm install bitsensor-node-js-middleware npm install bitsensor-node-js-logger

Create a config.json file.

{
  "uri": "http://bitsensor.io/api/",
  "user": "your_username",
  "apiKey": "your_api_key",
  "mode": "on",
  "connectionFail": "block",
  "ipAddressSrc": "remoteAddr",
  "nodeApi": "http" or "hapi"
}

The server code looks like this

require('bitsensor-node-js-core/core/init');
require('bitsensor-node-js-http/core/init');
require('bitsensor-node-js-middleware/core/init');
require('bitsensor-node-js-logger/core/logger');

var bitsensorParser = require('bitsensor-node-js-middleware/core/bitsensor-parser');
var http = require('http');
var express = require('express');
var app = express();

//express middleware
app.use(bitsensorParser);
app.use(bitsensorFlash);

//routes

//express error middleware

http.createServer(app).listen(8080, function () {
    console.log('Server listening on http://localhost:8080');
});

BitSensor has implemented its own error handle middleware, so do not forget to call next(err); in your custom error handle middleware.