@cfware/koa-daemon
v0.1.0
Published
Koa Daemon Base Class
Downloads
5
Readme
@cfware/koa-daemon
Koa Daemon Base Class
Install @cfware/koa-daemon
npm i --save @cfware/koa-daemon
Usage
'use strict';
const koaDaemon = require('@cfware/koa-daemon');
class MyDaemon extends koaDaemon {
constructor(listenAddr) {
super(listenAddr);
this.on('started', () => {
console.log(`Started, listening on http://localhost:${daemon.boundAddress.port}/`);
/* stop server and end client connections on SIGINT or SIGTERM. */
process.on('SIGINT', () => daemon.stop());
process.on('SIGTERM', () => daemon.stop());
});
this.on('stopped', () => console.log('Stopped Daemon'));
}
start() {
this.app.use(ctx => ctx.body = 'Hello World!');
super.start();
}
}
const daemon = new MyDaemon({port: 0});
daemon.start();
Running tests
Tests are provided by eslint and mocha.
npm install
npm test