Is it possible to unload modules in nodejs?
In other words: clear event listeners, timeouts, and intervals.
These modules are "sub-files" of my project, and i could overwrite the .on()
, and .once()
, but what about timeouts and intervals?
Is it possible to unload modules in nodejs?
In other words: clear event listeners, timeouts, and intervals.
These modules are "sub-files" of my project, and i could overwrite the .on()
, and .once()
, but what about timeouts and intervals?
No, not that I'm aware of.
You can remove all event listeners on an emitter by calling myEmitter.removeAllListeners()
. As for clearing the timeouts and intervals, call clearTimeout(timeoutName)
and clearInterval(intervalName)
respectively.
Example:
var x = 0;
var myInterval = setInterval(function(){
console.log('hello');
if (x > 5) clearInterval(myInterval);
x += 1;
},1000);
Hopefully this helps.