https://github.com/firstandthird/hapi-method-events
Hapi plugin to execute a method when an event fires
https://github.com/firstandthird/hapi-method-events
hapi-plugin hapi-v17
Last synced: 3 months ago
JSON representation
Hapi plugin to execute a method when an event fires
- Host: GitHub
- URL: https://github.com/firstandthird/hapi-method-events
- Owner: firstandthird
- License: mit
- Created: 2017-12-27T04:52:45.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-02-25T22:16:39.000Z (over 4 years ago)
- Last Synced: 2025-03-04T09:40:25.189Z (3 months ago)
- Topics: hapi-plugin, hapi-v17
- Language: JavaScript
- Size: 11.7 KB
- Stars: 0
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# hapi-method-events
A [hapi](https://hapi.dev/) plugin that makes it easy to create
response handlers for server events## Installation
```console
npm install hapi-method-events
```## Usage
```javascript
const plugin = require('hapi-method-events');
const server = new hapi.Server({ });// create a server event:
server.event('user.add');// create one or more server methods to respond to the event:
server.method('userAddHandler', (string) => {
console.log(string);
});
server.method('anotherUserAddHandler', (data) => {
console.log(data.string2);
});// register the plugin and specify server methods to call
// in the 'events' field
await server.register({
plugin,
options: {
events: [{
event: 'user.add',
// notice that the method is specified as a string
// and you can choose what value to pass to it
// when the event is emitted:
method: 'userAddHandler(data.string1)'
},
{
event: 'user.add',
method: 'anotherUserAddHandler(data)'
}]
}
});// now call the event!
await server.events.emit('user.add', {
data: {
string1: 'Hello World!',
string2: 'Hello Again!'
}
});
```## Options
- __events__ (required)
A list of events and methods to call for those events. The events should be specified as string.
- __verbose__
In verbose mode, hapi-method-events will print out the events and command string being executed.
By default this is set to false.