Skip to content
Related Articles
Open in App
Not now

Related Articles

Difference Between EventEmitter and NodeEventTarget

Improve Article
Save Article
  • Last Updated : 01 Sep, 2020
Improve Article
Save Article

EventEmitter: All EventEmitters emit the event ‘newListener‘ when new listeners are added and ‘removeListener‘ when existing listeners are removed. It is defined and exposed by the events module:

To import EventEmitter, use the following import statement:

const EventEmitter = require('events');

NodeEventTarget: The EventTarget and Event objects are a Node.js-specific implementation of the EventTarget Web API that is exposed by some Node.js core APIs.

Difference between EventEmitter and NodeEventTarget:

Event EmitterNode Event Target
It is inherited from the events Module of JavaScript.It is a modified subset of EventEmitter API and inherited from it.
It implements is-a relationship with the events Module.It implements is-a relationship with the EventTarget API.
In eventEmitter, for the same event, we can allow multiple listeners to be registered.Any listener can be registered once per event type and it gets ignored if attempted to register a listener multiple times.
It emulates the most from Events such as ‘error’, ‘Classes’, Emits, etc. It does not emulate the full EventEmitter APIs like prependListener(), prependOnceListener(), rawListeners(), etc.
Its default behavior is to log information and end the current execution.For ‘error‘ type events, it does not implement any default behavior.
 If an error occurs within an EventEmitter instance, then the typical action is for an ‘error’ event to be emitted. It supports EventListener objects and functions as handlers for all event types.
 All EventEmitter emit the event ‘newListener’, when new listeners are added and ‘removeListener’ when listeners are removed.It isn’t an instance of EventEmitter and in most cases, it can’t be used in place of an EventEmitter.


  eventName, listener)


  type, listener[, options])


My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!