Tag logo

Hide MaxListenersExceededWarning warnings of Node.js

Jul 22, 2024/
#nodejs
/-1 min

When working with Node.js, you must have come across the following warning.

MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 input listeners added to [EventEmitter]. Use emitter.setMaxListeners() to increase limit.

You can increase the limit to get rid of this warning. But keep in mind that this can create a memory leak. Don't use it to sweep under the rug! I used it to hide logs that show up in cli tool.

1import events from 'events';
2events.EventEmitter.prototype.setMaxListeners(30);