Listen to All Emitted Events in Node.js

I know this is a bit old, but what the hell, here is another solution you could take.

You can easily monkey-patch the emit function of the emitter you want to catch all events:

function patchEmitter(emitter, websocket) {
  var oldEmit = emitter.emit;

  emitter.emit = function() {
      var emitArgs = arguments;
      // serialize arguments in some way.
      ...
      // send them through the websocket received as a parameter
      ...
      oldEmit.apply(emitter, arguments);
  }
}

This is pretty simple code and should work on any emitter.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)