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

后端 未结 17 1809
我寻月下人不归
我寻月下人不归 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:36

    I am not 100% certain of what you mean by 'invalidate', but you can add the following above the require statements to clear the cache:

    Object.keys(require.cache).forEach(function(key) { delete require.cache[key] })
    

    Taken from @Dancrumb's comment here

提交回复
热议问题