drex - "dynamic require() extension". Dynamic version of Node's require() - 
loads fresh copy of the module every time the module file is changed.

https://github.com/yuryb/drex

example of frequently updated/added socket.io event handlers:

io.sockets.on('connection', function (socket) {
  // I need to do many things here, and these things change all the time!
  // If I use something like "forever", or "supervisor" to re-start my Node 
process every time 
  // when things here should change, all active sessions will be killed!
  // Oh, no, no, no!
  // All I want to do here, most of the time, is to put new event handler, 
which existing sessions 
  // do not even know about!

  drex.require('./my_module_with_event_handlers_which_I_always_change.js', 
function(mymod) {
      // here I can start calling methods from my module like there is no 
tomorrow!
      // and I'm guaranteed that every time I update my module, sessions which 
will come here after the update
      // will get the new code, but sessions which were opened before the 
update will still be working with the
      // code which existed in my module when these sessions were created. 
That's fair!
  });



On Monday, January 9, 2012 3:01:41 AM UTC-8, Tamil Selvan wrote:
>
> 'index.js' 
> var sample = require('sample'); 
> console.log(sample); 
> sample.setter(12); 
> var other = require('other'); 
> console.log(sample.getter()); 
> _________________________________________ 
>
> 'node_modules/sample.js' 
> var test = function () { 
>                                  var test; 
>                                  return { 
>                                     getter : function () { 
>                                                   return test; 
>                                                 }, 
>                                    setter : function (val) { 
>                                                     test = val; 
>                                               } 
>                                   }; 
> }; 
>
> module.exports = new test(); 
> ------------------------------------------------------------------------ 
> 'node_modules/other.js' 
> var sample = require('sample'); 
> console.log('hai tamilselvan it is working :)'); 
> console.log(sample.getter()); 
> sample.setter(13); 
> ------------------------------------------------------------------------- 
> Output 
> { getter: [Function], setter: [Function] } 
> hai tamilselvan it is working :) 
> 12 
> 13 
>
> How does that 12 and 13 getting updated?  Is that sample.js behaves 
> like singleton although i give new test() ? 
>
> Or is it because of caching of node modules? 
>
> I'm glad it works the way i wished to but I wanna know how... 
>
> BTW What is the main difference between exports and module.exports? 
>
>

-- 
-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: 
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 post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
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 [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to