July 22, 2024 /
1 min /
#nodejs
#javascript
#events
Hide max listeners exceeded warnings of Node.js
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.
import events from 'events';events.EventEmitter.prototype.setMaxListeners(30);