Files
30-seconds-of-code/snippets/require-uncached.md
2023-04-28 22:29:23 +03:00

521 B

title, type, tags, author, cover, dateModified
title type tags author cover dateModified
Uncached module require snippet
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