npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nodejs-event-manager

v1.1.2

Published

A nodeJS Event Manager to emit, and listen event through nodeJS

Downloads

314

Readme

NodeJS Event Manager

Build Status Maintainability Test Coverage

A NodeJS Event Manager using builtin NodeJS Events.

The main purpose of this package, is to facilitate the use of events, in a node JS application.

It implements the same "api" ("interface") as rabbitmq-event-manager so you can easily switch from NodeJS to RabbitMQ of vice-versa.

It can be usefull for testing purpose, but also in order to start quickly with nodeJS and if your application is getting bigger and you want to externalize some parts, you can deploy a RabittMQ and make your applications communicate together

Install

npm install nodejs-event-manager

Or with Yarn

yarn add nodejs-event-manager

Basic Example

  • Initialize
import EventManager from "nodejs-event-manager";
const myEventManager = new EventManager();
myEventManager
  .initialize()
  .then(() => {
    /** Do something after initialization */
  })
  .catch(err => {
    /** An error occured while initialization */
  });
  • Consumer
import EventManager from 'nodejs-event-manager';
const myEventManager = new EventManager({appName:'CONSUMER');
myEventManager.on('MY_EVENT_NAME', async (payload)=>{
    console.log(payload);
});
  • Producer
import EventManager from "nodejs-event-manager";
const myEventManager = new EventManager({ appName: "PRODUCER_1" });

myEventManager.emit("MY_EVENT_NAME", payload);

NOTE: :warning: A very good convention may be to prefix the name of the event with the emitter application name, for example : PRODUCER_1.MY_EVENT_NAME but it's not mandatory.

Then we can create new Consumer and listen the same event :

import EventManager from 'nodejs-event-manager';
const myEventManager = new EventManager({appName:'OTHER_CONSUMER');
myEventManager.on('MY_EVENT_NAME', async (payload)=>{
    console.log(payload);
});

Options

| Name | Type | Default | Description | | --------------------- | --------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------- | | appName | String | - | The name of the application (used for naming exchanges and queues). | | metas | boolean or (function) | true | Weither or not to add _metas infirmations in the event, If a function this returned value, will become the _metas object (see ) | | logPrefix | string | [RABBITMQ] | The text that will be printed before the error log | | logLevel | string | error | The log Level (see winston logLevels) | | logTransportMode | string | console | Mute (no log), or output to console. Possible values are ("console" or "mute") | | defaultResponseSuffix | string | '.RESPONSE' | The suffix to add to the response event name. | | emitAndWaitTimeout | number | 30000 | the timeout when emit and wait |

Metas Informations

By defaut, some metas data are added to the payload :

  • guid : A unique id generated, to be able to debug for example, or for following the event.
  • timestamp : A number of milliseconds elapsed since January 1, 1970 00:00:00 UTC. (Date.now())
  • name : A string which is the name of the emitted event.
  • applicationName: The value of the application which emits the Event.

So if your payload is :

{
  userId: 42;
}

With Metas data it will be :

{
    _metas:{
        guid: '465e008c-d37f-4e31-b494-023e6d187946',
        name: 'MY_EVENT_NAME',
        timestamp: 1519211809934,
        applicationName: 'PRODUCER_1'
    },
    userId:42
}

You can remove metas informations by settings the option value "metas" to false.

You can also override the metas generation by giving a function as metas options value (on the emitter side only, as the event is generated there).

With no metas

import EventManager from "rabbitmq-event-manager";
const myEventManagerWithNoMetas = new EventManager({
  url: "amqp://localhost",
  appName: "PRODUCER_1",
  metas: false
});
const payload = { userId: 42 };
myEventManagerWithNoMetas.emit("MY_EVENT_NAME", payload);
// Payload will be
// {
//    userId:42
// }

Override Metas

import EventManager from "rabbitmq-event-manager";
const myEventManagerOverrideMetas = new EventManager({
  url: "amqp://localhost",
  appName: "PRODUCER_1",
  metas: sourceMetas => {
    // sourceMetas contains the default metaa
    return {
      ...sourceMetas,
      otherProperty: "MyValue"
    };
  }
});
const payload = { userId: 42 };
myEventManagerOverrideMetas.emit("MY_EVENT_NAME", payload);
// Payload will be
// {
//    _metas: {
//        guid : '465e008c-d37f-4e31-b494-023e6d187947'
//        name: 'MY_EVENT_NAME',
//        timestamp: 1519211809934,
//        otherProperty:'MyValue'
//    }
//    userId:42
// }

Emit and wait

  • since version 1.1.0 An example with a test :
it("Should be able to emit and wait for response two times", async () => {
  /** given */

  /** when */
  eventManager.on("add", async payload => {
    return { result: payload.a + payload.b };
  });

  await pause(500);
  const add1 = await eventManager.emitAndWait("add", { a: 3, b: 42 });
  const add2 = await eventManager.emitAndWait("add", { a: 3, b: 3 });
  await pause(500);
  /** then */
  expect(add1.result).to.equal(45);
  expect(add2.result).to.equal(6);
});