https://github.com/cilindrox/hapi-emitter
A hapi EventEmitter plugin
https://github.com/cilindrox/hapi-emitter
hapi-plugin hapijs hapijs-plugin
Last synced: 7 months ago
JSON representation
A hapi EventEmitter plugin
- Host: GitHub
- URL: https://github.com/cilindrox/hapi-emitter
- Owner: cilindrox
- License: mit
- Created: 2016-03-08T14:28:36.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2022-04-10T05:11:34.000Z (almost 4 years ago)
- Last Synced: 2025-04-22T13:09:19.952Z (10 months ago)
- Topics: hapi-plugin, hapijs, hapijs-plugin
- Language: JavaScript
- Size: 376 KB
- Stars: 1
- Watchers: 0
- Forks: 4
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-emitter
A hapi EventEmitter plugin
[](https://circleci.com/gh/cilindrox/hapi-emitter)
## Installation
```
npm install --save hapi-emitter
```
## Versions
Use v1.x.x in consumers using Hapi 16.
Use v2.x.x in consumers using Hapi 17+.
## Example
```js
'use strict';
const Hapi = require('hapi');
const server = new Hapi.Server();
server.connection({ host: 'localhost' });
// Register the plugin
server.register({
register: require('hapi-emitter'),
options: {
name: 'events'
}
}, (err) => {
if (err) {
console.error(err);
}
else {
server.start(() => {
console.info(`Server started at ${server.info.uri}`);
});
}
});
// Declare a route that uses it
server.route({
method: 'POST',
path: '/events',
handler: myHandler
});
// Access the EventEmitter instance
const myHandler = (request, reply) => {
const events = request.server.events;
events.emit('hello', request.payload.world);
return reply().code(202);
};
server.start(function() {
console.log(`Server started at ${server.info.uri}`);
});
```
## Tests
To run the test suite, first install the dependencies, then run `npm test`:
```bash
$ npm install
$ npm test
```