auto-reload for module reload without shutdown

36 views
Skip to first unread message

Lellansin Huang

unread,
Sep 18, 2014, 11:41:59 PM9/18/14
to nod...@googlegroups.com
Um.. I write a module for auto reload module without shutdown the server. It can be used like this:

var reload = require('auto-reload');
var data = reload('./data', 3000); // reload every 3 secs

// print data every sec
setInterval(function() {
    console.log(data);
}, 1000);
And if you update the file data.json or .js, the var data can be auto reloaded.

I did this by;

delete require.cache[whole];
var update = require(whole);
// clone new module data to old reference
clone(module, update);
It's very simple, you can see more detail on https://github.com/Lellansin/node-reload .

I just want to discuss the possible negative effect or problem, and how to fix or improve. 

Thanks a lot if you reply.

Ingwie Phoenix

unread,
Sep 19, 2014, 4:21:11 AM9/19/14
to nod...@googlegroups.com
Wow! This might take out the need to have a watchdog process to restart the server. Very nice!
--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/42d5a93e-d99b-411f-87da-5deb506b5935%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages