Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hapi-emitter

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hapi-emitter

A hapi EventEmitter plugin

  • 4.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hapi-emitter

A hapi EventEmitter plugin

CircleCI

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

'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:

$ npm install
$ npm test

Keywords

FAQs

Package last updated on 23 Jul 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc