# hapi-signals

> Signals as events for Hapi

Latest version **0.0.3** (published 2016-12-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install hapi-signals
pnpm add hapi-signals
yarn add hapi-signals
bun add hapi-signals
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2016-12-23 |
| First published | 2016-12-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Author | Sebastian Garrido |
| Maintainers | sebasgarcep |

## Links

- npm: https://www.npmjs.com/package/hapi-signals
- Repository: https://github.com/sebasgarcep/hapi-signals
- Issues: https://github.com/sebasgarcep/hapi-signals/issues
- npm.io page: https://npm.io/package/hapi-signals

## Dependencies (2)

- [joi](https://npm.io/package/joi.md) ^10.1.0
- [hoek](https://npm.io/package/hoek.md) ^4.1.0

## Recent versions

- 0.0.3 (latest) — 2016-12-23
- 0.0.2 — 2016-12-22
- 0.0.1 — 2016-12-22

## README

# hapi-signals

Signals and events for Hapi.

### Install

```bash
$ npm install hapi-signals
```


### Usage

It decorates the server with the method _addSignal_. This method takes a string and adds a signals with that name. It also exposes the signals and decorates the requests with the _signals_ object.

A signal has the following methods:

- dispatch: fires all callbacks with the arguments provided to this method.
- add: registers a callback to be called when this signal dispatches. The call back takes as arguments whatever is passed to the dispatch method.
- once: same as add but runs only once

The plugin can also be passed the following options:

- signals: string or array of strings of names of signals to add during registration

### Example

```javascript
const Hapi = require('hapi');

const server = new Hapi.Server(/* options */);

// some other stuff ...

server.register(require('hapi-signals'), err => {
  if (err) throw err;

  server.addSignal('addedUser');

  server.plugins.signals.addedUser.add(name => console.log(`${name} `));

  server.plugins.signals.addedUser.dispatch('Tom'); // logs to console 'Tom'

  server.route({
    method: 'post',
    path: '/signup',
    handler: (request, reply) => {
      // logs to console whatever the name is
      request.signals.addedUser(request.payload.name);

      // rest of your logic ...

    },
  });

  server.start();
});
```


### License

MIT

---
_Source: https://npm.io/package/hapi-signals · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
