Rename js snippets
This commit is contained in:
25
snippets/js/s/uncached-module-require.md
Normal file
25
snippets/js/s/uncached-module-require.md
Normal file
@ -0,0 +1,25 @@
|
||||
---
|
||||
title: Uncached module require
|
||||
type: snippet
|
||||
language: javascript
|
||||
tags: [node]
|
||||
author: chalarangelo
|
||||
cover: tea-laptop-table
|
||||
dateModified: 2020-09-15T16:28:04+03:00
|
||||
---
|
||||
|
||||
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
|
||||
```
|
||||
Reference in New Issue
Block a user