I was trying to create an IRC bot written in Javascript + NodeJS. This bot should be able to load plugins while running and should be able to reload the same plugin after changes etc.
What works?
Loading files at runtime + executing its code.
What's wrong?
After loading the same plugin again if still executes my code, but now it happens twice or nth times I load the plugins.
Current code:
bot.match(/\.load/i, function(msg) {
    require('./plugins/plug.js')(this);
});
module.exports  = function(bot) {
    bot.match(/\.ping/i, function(msg) {
    msg.reply('pong');
});
So, is there any way to fix my issues and make this work?
P.s. I'm using IRC-JS as a base for this bot.
updated, fixed:
Even changes to that file are ignored, so it must be something like a cache.
Fixed by clearing the require.cache
 
     
    