node.js require() cache - possible to invalidate?

后端 未结 17 1813
我寻月下人不归
我寻月下人不归 2020-11-22 06:52

From the node.js documentation:

Modules are cached after the first time they are loaded. This means (among other things) that every call to require(\'

17条回答
  •  醉梦人生
    2020-11-22 07:35

    Following two step procedure is working perfectly for me.

    After changing Model file i-e 'mymodule.js' dynamically, you need to Delete precompiled model in mongoose model first then reload it using require-reload

    Example:
            // Delete mongoose model
            delete mongoose.connection.models[thisObject.singular('mymodule')]
    
            // Reload model
            var reload = require('require-reload')(require);
            var entityModel = reload('./mymodule.js');
    

提交回复
热议问题