@bitskyai/producer-sdk v0.2.2
BitSky Producer SDK
const baseservice = require('@bitskyai/producer-sdk');
baseservice.express();
baseservice.listen();Installation
This is a Node.js module available through the npm registry.
Before installing, download and install Node.js.
Node.js 12 or higher is required.
If this is a brand new project, make sure to create a package.json first with
the npm init command.
Installation is done using the
npm install command:
$ npm install @bitskyai/producer-sdkbitsky-service-producer is a good example
Features
APIs
express
Create an ExpressJS app, and configure routes, JSON limit, static folder.
const baseservice = require("@bitskyai/producer-sdk");
baseservice.express();Routes
/: return index page/health: return health status of this server/producer: return current producer configuration. If producer don't exist then return empty/log/combined.log: All logs for debug purpose/log/error.log: Error logs
JSON Limit
100mb
Returns
Object: An Express Application Instance. You can use express API to add additional configuration
type
Get or set producer type. Currently support type is ['HEADLESSBROSWER', 'SERVICE']. Default is SERVICE type
const baseservice = require("@bitskyai/producer-sdk");
baseservice.express();
baseservice.type("HEADLESSBROWSER");Parameters
type:String- Optional
Returns
String|Object: Type string or BaseService
worker
Get or set worker. Worker responses for collect tasks. Default it uses service worker.
const { headlessWorker } = require("./workers/headlessWorker");
const baseservice = require("@bitskyai/producer-sdk");
baseservice.express();
baseservice.type("HEADLESSBROWSER");
baseservice.worker(headlessWorker);Parameters
worker: Object: worker object- Optional
Returns
Object: Woker object or BaseService
getPublic
Return absolute path to public folder, anything you store in public folder, you can access by /<path_to_file>.
Returns
String: Absolute path topublicfolder
listen
Start server, similar with express.listen
const baseservice = require('@bitskyai/producer-sdk');
baseservice.express();
baseservice.listen();or
const baseservice = require('@bitskyai/producer-sdk');
baseservice.express();
baseservice.listen(9090);Parameters
port: Number: Default will get fromprocess.env.PORT, otherwise8090- Optional
Returns
Promise: Start successful, thenresolve(true), otherwisereject(err)
logger
Return winston logger, you can use this to add your logs, and view by /log/combined.log or /log/error.log
const baseservice = require('@bitskyai/producer-sdk');
const logger = baseservice.logger;
logger.info('Just for test');Returns
Object:winstonlogger instance