bitsensor

0.9.0 • Public • Published

BitSensor Node.js Plugin

Usage

Add bitsensor to your dependencies.

npm install bitsensor --save

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"
}

Run BitSensor inside your handleRequest() method.

var BitSensor = require('bitsensor/core/bitsensor');
var HttpHandler = require('bitsensor/handler/http-handler');
var fs = require('fs');
 
var http = require('http');
 
// Start BitSensor with the path of the config.json file as argument
var sensor = new BitSensor(fs.realpathSync('config.json'));
 
function handleRequest(request, response) {
    // Use the handler for http server
    sensor.addHandler(new HttpHandler(request, response));
    sensor.runHandlers();
    sensor.authorize(function () {
        // DoYaThing
    }, response);
}
 
var server = http.createServer(handleRequest);
 
server.listen(8080, function () {
    console.log('Server listening on http://localhost:8080');
});

Readme

Keywords

Package Sidebar

Install

npm i bitsensor

Weekly Downloads

1

Version

0.9.0

License

MIT

Last publish

Collaborators

  • bitsensor-bram