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

You can use this to delete its entry in the cache:

delete require.cache[require.resolve('./b.js')]

require.resolve() will figure out the full path of ./b.js, which is used as a cache key.

Leave a Comment