Files
30-seconds-of-code/js/s/require-uncached.md
Angelos Chalaris 5c913d20bd Reorganize snippets
2023-05-03 21:19:02 +03:00

542 B

title, type, language, tags, author, cover, dateModified
title type language tags author cover dateModified
Uncached module require snippet javascript
node
chalarangelo curve 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