FAQ
I did some research in the group and it appears someone had a similar
question about unloading modules that were loaded with require.

Am I correct in reading that the use of nodules would allow me to
require('./module1') then dump the entire contents of that
module programmaticly at a later time? Then reload it if I felt like it,
all within the same node process.

It seems I could build a simple app server with dynamic modules can be done
like so:

I have this working pretty well except for the unloading piece. Is this
possible or do I have to find a mechanism to bounce the nodes?


var loadedModules = {};

on('load', function(moduleName) {
var module = require(moduleName);
module.start();
loadedModules[ moduleName ] = module;
});

on('unload', function(moduleName) {
// unload here..
});

I completely realize that I am oversimplifying so I am hoping to get
straightened out.

--
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 nodejs@googlegroups.com
To unsubscribe from this group, send email to
nodejs+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Search Discussions

  • Darcy at Jun 14, 2012 at 2:40 am
    delete require.cache[the_absolute path_of_module];

    is it what you want?
    On Thursday, June 14, 2012 3:40:55 AM UTC+8, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a similar
    question about unloading modules that were loaded with require.

    Am I correct in reading that the use of nodules would allow me to
    require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I felt like it,
    all within the same node process.

    It seems I could build a simple app server with dynamic modules can be
    done like so:

    I have this working pretty well except for the unloading piece. Is this
    possible or do I have to find a mechanism to bounce the nodes?


    var loadedModules = {};

    on('load', function(moduleName) {
    var module = require(moduleName);
    module.start();
    loadedModules[ moduleName ] = module;
    });

    on('unload', function(moduleName) {
    // unload here..
    });

    I completely realize that I am oversimplifying so I am hoping to get
    straightened out.
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Ben at Jun 14, 2012 at 6:57 am
    I'm interested in this question too. I tried it once, but all the async
    operations started by the modules remained active even after "unloading"
    it. Try for example a simple setInterval() that writes something to the log
    every second, in the module - when you unload the module, the timer is
    still running.

    Is there a better way to do it?


    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a similar
    question about unloading modules that were loaded with require.

    Am I correct in reading that the use of nodules would allow me to
    require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I felt like it,
    all within the same node process.
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Yogesh agrawal at Jun 14, 2012 at 7:02 am
    delete require.cache is not good way to unload.

    Some times module doesn't get unloaded after deleting it from cache.
    Modules api lacks unload method :(
    On Thu, Jun 14, 2012 at 11:28 AM, Ben wrote:

    I'm interested in this question too. I tried it once, but all the async
    operations started by the modules remained active even after "unloading"
    it. Try for example a simple setInterval() that writes something to the log
    every second, in the module - when you unload the module, the timer is
    still running.

    Is there a better way to do it?


    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a similar
    question about unloading modules that were loaded with require.

    Am I correct in reading that the use of nodules would allow me to
    require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I felt like it,
    all within the same node process.

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en


    --
    Yogesh Agrawal
    +91-9351507770

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Dan Milon at Jun 14, 2012 at 8:19 am
    What is the use case of unloading a module?
    On 06/14/2012 10:02 AM, yogesh agrawal wrote:
    delete require.cache is not good way to unload.

    Some times module doesn't get unloaded after deleting it from cache.
    Modules api lacks unload method :(

    On Thu, Jun 14, 2012 at 11:28 AM, Ben wrote:

    I'm interested in this question too. I tried it once, but all the
    async operations started by the modules remained active even after
    "unloading" it. Try for example a simple setInterval() that writes
    something to the log every second, in the module - when you unload
    the module, the timer is still running.

    Is there a better way to do it?



    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a
    similar question about unloading modules that were loaded with
    require.

    Am I correct in reading that the use of nodules would allow me
    to require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I
    felt like it, all within the same node process.

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en




    --
    Yogesh Agrawal
    +91-9351507770
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Mgutz at Jun 14, 2012 at 3:18 pm
    In our case, our xml builder like templates are javascript modules loaded
    via require. Templates in development mode should not be cached. `delete
    require.cache` works for us.
    On Thursday, June 14, 2012 1:12:20 AM UTC-7, Dan Milon wrote:

    What is the use case of unloading a module?
    On 06/14/2012 10:02 AM, yogesh agrawal wrote:
    delete require.cache is not good way to unload.

    Some times module doesn't get unloaded after deleting it from cache.
    Modules api lacks unload method :(

    On Thu, Jun 14, 2012 at 11:28 AM, Ben <thebuckst0p@gmail.com
    wrote:

    I'm interested in this question too. I tried it once, but all the
    async operations started by the modules remained active even after
    "unloading" it. Try for example a simple setInterval() that writes
    something to the log every second, in the module - when you unload
    the module, the timer is still running.

    Is there a better way to do it?



    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a
    similar question about unloading modules that were loaded with
    require.

    Am I correct in reading that the use of nodules would allow me
    to require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I
    felt like it, all within the same node process.

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en




    --
    Yogesh Agrawal
    +91-9351507770
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Dominic Tarr at Jun 15, 2012 at 2:42 pm
    what you _could_ do, is instrument the code by parsing and inserting
    additional calls.
    with this technique you can add counters that make it safe to run
    untrusted code.

    so you can prevent things like: while (true);

    which would loop forever. you could also use this technique to abort
    any io operation,
    and to clearTimeout etc.

    of course, most people are not crazy enough to pull something like this off.

    you need to be a bit of a mad scientist.

    like substack!
    https://github.com/substack/node-falafel
    https://github.com/substack/node-stackedy


    On Fri, Jun 15, 2012 at 3:18 AM, mgutz wrote:
    In our case, our xml builder like templates are javascript modules loaded
    via require. Templates in development mode should not be cached. `delete
    require.cache` works for us.
    On Thursday, June 14, 2012 1:12:20 AM UTC-7, Dan Milon wrote:

    What is the use case of unloading a module?
    On 06/14/2012 10:02 AM, yogesh agrawal wrote:
    delete require.cache is not good way to unload.

    Some times module doesn't get unloaded after deleting it from cache.
    Modules api lacks unload method :(

    On Thu, Jun 14, 2012 at 11:28 AM, Ben <thebuckst0p@gmail.com
    wrote:

    I'm interested in this question too. I tried it once, but all the
    async operations started by the modules remained active even after
    "unloading" it. Try for example a simple setInterval() that writes
    something to the log every second, in the module - when you unload
    the module, the timer is still running.

    Is there a better way to do it?



    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a
    similar question about unloading modules that were loaded with
    require.

    Am I correct in reading that the use of nodules would allow me
    to require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I
    felt like it, all within the same node process.

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en




    --
    Yogesh Agrawal
    +91-9351507770
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Rubyonrailsx at Jun 14, 2012 at 1:17 pm
    Does this mean NodeJs can change its code on-the-fly?

    --
    rubyonrailsx
    Sent with Sparrow (http://www.sparrowmailapp.com/?sig)

    On Thursday, June 14, 2012 at 3:02 PM, yogesh agrawal wrote:

    delete require.cache is not good way to unload.

    Some times module doesn't get unloaded after deleting it from cache. Modules api lacks unload method :(
    On Thu, Jun 14, 2012 at 11:28 AM, Ben (mailto:thebuckst0p@gmail.com)> wrote:
    I'm interested in this question too. I tried it once, but all the async operations started by the modules remained active even after "unloading" it. Try for example a simple setInterval() that writes something to the log every second, in the module - when you unload the module, the timer is still running.

    Is there a better way to do it?


    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:
    I did some research in the group and it appears someone had a similar question about unloading modules that were loaded with require.

    Am I correct in reading that the use of nodules would allow me to require('./module1') then dump the entire contents of that module programmaticly at a later time? Then reload it if I felt like it, all within the same node process.
    --
    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 nodejs@googlegroups.com (mailto:nodejs@googlegroups.com)
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com (mailto:nodejs%2Bunsubscribe@googlegroups.com)
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en


    --
    Yogesh Agrawal
    +91-9351507770
    --
    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 nodejs@googlegroups.com (mailto:nodejs@googlegroups.com)
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com (mailto:nodejs+unsubscribe@googlegroups.com)
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
  • Matt at Jun 14, 2012 at 1:45 pm
    Of course it does. It's a dynamic language. You can redefine any function
    at any time.
    On Thu, Jun 14, 2012 at 3:08 AM, rubyonrailsx wrote:

    Does this mean NodeJs can change its code on-the-fly?

    --
    rubyonrailsx
    Sent with Sparrow <http://www.sparrowmailapp.com/?sig>

    On Thursday, June 14, 2012 at 3:02 PM, yogesh agrawal wrote:

    delete require.cache is not good way to unload.

    Some times module doesn't get unloaded after deleting it from cache.
    Modules api lacks unload method :(

    On Thu, Jun 14, 2012 at 11:28 AM, Ben wrote:

    I'm interested in this question too. I tried it once, but all the async
    operations started by the modules remained active even after "unloading"
    it. Try for example a simple setInterval() that writes something to the log
    every second, in the module - when you unload the module, the timer is
    still running.

    Is there a better way to do it?



    On Wednesday, June 13, 2012 4:40:55 PM UTC-3, Andrew Finnell wrote:

    I did some research in the group and it appears someone had a similar
    question about unloading modules that were loaded with require.

    Am I correct in reading that the use of nodules would allow me to
    require('./module1') then dump the entire contents of that
    module programmaticly at a later time? Then reload it if I felt like it,
    all within the same node process.

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en




    --
    Yogesh Agrawal
    +91-9351507770

    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en


    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en
    --
    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 nodejs@googlegroups.com
    To unsubscribe from this group, send email to
    nodejs+unsubscribe@googlegroups.com
    For more options, visit this group at
    http://groups.google.com/group/nodejs?hl=en?hl=en

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupnodejs @
categoriesnodejs
postedJun 13, '12 at 7:40p
activeJun 15, '12 at 2:42p
posts9
users9
websitenodejs.org
irc#node.js

People

Translate

site design / logo © 2022 Grokbase