Skip to content

Instantly share code, notes, and snippets.

@victorferreira
Created May 23, 2024 17:31
Show Gist options
  • Save victorferreira/a5e404b1dad1d1c204dcb26bfc3678e1 to your computer and use it in GitHub Desktop.
Save victorferreira/a5e404b1dad1d1c204dcb26bfc3678e1 to your computer and use it in GitHub Desktop.
JS: reload module reference
let storage = require("./storage");
storage.add("hello");
console.log(storage.size()); // 1
storage.add("hello1");
console.log(storage.size()); // 2
storage = undefined;
delete require.cache[require.resolve("./storage")];
storage = require("./storage");
console.log(storage.size()); // 0
const arr = [];
function add(value) {
arr.push(value);
}
function size() {
return arr.length;
}
exports.add = add;
exports.size = size;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment