DEV Community

Discussion on: Why and how to use the the Node.js Event Emitter in real projects?

Collapse
 
urielsouza29 profile image
Uriel dos Santos Souza

how to remove in real projects?

Collapse
 
amrelmohamady profile image
Amr Elmohamady

In such usecases, no need to remove event listeners and once can be used.
But, If you need to remove listeners, you can use removeListener and the listener function should be defined on its own like:

const eventHandler = () => { /* Logic */ };
Eventemitter.on("EVENT_NAME", eventHandler);
EventEmitter.removeListener("EVENT_NAME", eventHandler);
Enter fullscreen mode Exit fullscreen mode
Collapse
 
amrelmohamady profile image
Amr Elmohamady

What do you mean?

Collapse
 
urielsouza29 profile image
Uriel dos Santos Souza

How to properly remove event listeners in node js eventemitter?