Files
30-seconds-of-code/snippets/js/s/require-uncached.md
2023-05-10 22:35:09 +03:00

553 B

title, type, language, tags, author, cover, dateModified
title type language tags author cover dateModified
Uncached module require snippet javascript
node
chalarangelo tea-laptop-table 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.
const requireUncached = module => {
  delete require.cache[require.resolve(module)];
  return require(module);
};
const fs = requireUncached('fs'); // 'fs' will be loaded fresh every time