Add requireUncached

This commit is contained in:
Angelos Chalaris
2020-08-07 15:49:39 +03:00
parent 166a6f9f70
commit 1ad5d1004d

View File

@ -0,0 +1,20 @@
---
title: requireUncached
tags: node,advanced
---
Loads a module after removing it from the cache (if exists).
Use `delete` to remove the module from the cache (if exists).
Use `require()` to load the module again.
```js
const requireUncached = module => {
delete require.cache[require.resolve(module)];
return require(module);
};
```
```js
const fs = requireUncached('fs'); // 'fs' will be loaded fresh every time
```