July 22, 2024

/ ~

Hide max listeners exceeded warnings of Node.js

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

Terminal window
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.

Terminal window
import events from 'events';
events.EventEmitter.prototype.setMaxListeners(30);