koa-notifier

0.1.1 • Public • Published

koa-notifier

Wrap node-notifier for koa, cute for test..

Install

npm i koa-notifier --save

Usage

notifier(options)

options is a obejct that key as status:

{
  '200': {
    title: 'success',
    message: 'LOL, have a nice day.',
    icon: __dirname + '/success.jpg',
    ...
  },
  '404': {
    title: 'Opps, 404',
    message: 'This page was not founded.',
    icon: __dirname + '/error.jpg',
    ...
  },
  '500': {
    title: '500!!!!!',
    message: 'What the fuck.',
    icon: __dirname + '/error.jpg',
    ...
  }
  ...
}

see node-notifier for more details.

Example

Default usage:

var koa = require('koa');
var route = require('koa-route');
var notifier = require('..');

var app = koa();

if (process.env.NODE_ENV !== 'production') {
  app.use(notifier());
}

app.use(route.get('/', function* () {
  this.body = 'Have a nice day!';
}));

app.use(route.get('/error', function* () {
  this.throw(400, 'Some errorrrr!');
}));

app.listen(3000, function () {
  console.log('listening on 3000.');
});

Or use custom options:

var koa = require('koa');
var route = require('koa-route');
var notifier = require('..');

var app = koa();

if (process.env.NODE_ENV !== 'production') {
  app.use(notifier({
    '200': {
      title: 'success',
      message: 'LOL, have a nice day.',
      icon: __dirname + '/success.jpg'
    },
    '404': {
      title: 'Opps, 404',
      message: 'This page was not founded.',
      icon: __dirname + '/error.jpg'
    },
    '500': {
      title: '500!!!!!',
      message: 'What the fuck.',
      icon: __dirname + '/error.jpg'
    }
  }));
}

app.use(route.get('/', function* () {
  this.body = 'Have a nice day!';
}));

app.use(route.get('/error', function* () {
  crash();
}));

app.listen(3000, function () {
  console.log('listening on 3000.');
});

Now, open your browser and type:

localhost:3000

200

localhost:3000/abc

404

localhost:3000/error

500

License

MIT

Package Sidebar

Install

npm i koa-notifier

Weekly Downloads

1

Version

0.1.1

License

none

Last publish

Collaborators

  • nswbmw