How to remove module after “require” in node.js?

后端 未结 5 1970
感动是毒
感动是毒 2020-11-29 00:27

Let say, after I require a module and do something as below:

var b = require(\'./b.js\');
--- do something with b ---

Then I want to take a

5条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-29 00:59

    I have found the easiest way to handle invalidating the cache is actually to reset the exposed cache object. When deleting individual entries from the cache, the child dependencies become a bit troublesome to iterate through.

    require.cache = {};

提交回复
热议问题