{"id":15552996,"url":"https://github.com/bahmutov/require-and-forget","last_synced_at":"2025-09-28T20:31:12.814Z","repository":{"id":57354202,"uuid":"102547089","full_name":"bahmutov/require-and-forget","owner":"bahmutov","description":"Require Node module and immediately remove it from module cache to force loading again next time","archived":false,"fork":false,"pushed_at":"2023-03-02T02:59:30.000Z","size":98,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-27T21:00:52.720Z","etag":null,"topics":["cache","load","node","npm","require","utility"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bahmutov.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-09-06T01:20:26.000Z","updated_at":"2023-03-02T02:59:00.000Z","dependencies_parsed_at":"2022-09-05T13:10:39.038Z","dependency_job_id":null,"html_url":"https://github.com/bahmutov/require-and-forget","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Frequire-and-forget","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Frequire-and-forget/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Frequire-and-forget/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bahmutov%2Frequire-and-forget/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bahmutov","download_url":"https://codeload.github.com/bahmutov/require-and-forget/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234558807,"owners_count":18852283,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cache","load","node","npm","require","utility"],"created_at":"2024-10-02T14:23:26.712Z","updated_at":"2025-09-28T20:31:12.424Z","avatar_url":"https://github.com/bahmutov.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# require-and-forget\n\n\u003e Require Node module and immediately remove it from module cache to force loading again next time\n\n[![NPM][npm-icon] ][npm-url]\n\n[![Build status][ci-image] ][ci-url]\n[![semantic-release][semantic-image] ][semantic-url]\n[![js-standard-style][standard-image]][standard-url]\n\nThis module is useful for testing when you want to force reloading and re-evaluating the\nNPM module.\n\n## Install\n\nRequires [Node](https://nodejs.org/en/) version 4 or above.\n\n```sh\nnpm install --save require-and-forget\n```\n\n## Use\n\nWhenever you want to get an exported value from a module, but not store it in\nthe Node's `require.cache`. Imagine we have a file that just exports a random value\n\n```js\n// random.js\nmodule.exports = Math.random()\n```\n\nOrdinarily, every `require('./random')` will get the same value because it will be stored\ncached in the Node's cache. The `./random.js` will not be evaluated every time you require it.\nInstead you can load and \"forget it\" to force re-evaluation.\n\n```js\nconst forget = require('require-and-forget')\nconst r1 = forget('./random')\nconst r2 = forget('./random')\n// r1 and r2 will be different\n// \"random.js\" will not be stored in the require.cache\n```\n\n## Related projects\n\n* [unload-me](https://github.com/bahmutov/unload-me) - the module itself forces Node's cache\n  to delete it after loading. Kind of `self-destruct`.\n* [Playing havoc with Node module system](https://glebbahmutov.com/blog/playing-havoc-with-node-module-system/)\n* [Hacking Node require](https://glebbahmutov.com/blog/hacking-node-require/)\n* [Faster Node app require](https://glebbahmutov.com/blog/faster-node-app-require/)\n* [node-hook](https://github.com/bahmutov/node-hook) - Run source transform function on node require call.\n\n## Debug\n\nRun code with `DEBUG=require-and-forget` environment variable\n\n### Small print\n\nAuthor: Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt; \u0026copy; 2017\n\n* [@bahmutov](https://twitter.com/bahmutov)\n* [glebbahmutov.com](https://glebbahmutov.com)\n* [blog](https://glebbahmutov.com/blog)\n\nLicense: MIT - do anything with the code, but don't blame me if it does not work.\n\nSupport: if you find any problems with this module, email / tweet /\n[open issue](https://github.com/bahmutov/require-and-forget/issues) on Github\n\n## MIT License\n\nCopyright (c) 2017 Gleb Bahmutov \u0026lt;gleb.bahmutov@gmail.com\u0026gt;\n\nPermission is hereby granted, free of charge, to any person\nobtaining a copy of this software and associated documentation\nfiles (the \"Software\"), to deal in the Software without\nrestriction, including without limitation the rights to use,\ncopy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the\nSoftware is furnished to do so, subject to the following\nconditions:\n\nThe above copyright notice and this permission notice shall be\nincluded in all copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES\nOF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT\nHOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,\nWHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\nFROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR\nOTHER DEALINGS IN THE SOFTWARE.\n\n[npm-icon]: https://nodei.co/npm/require-and-forget.svg?downloads=true\n[npm-url]: https://npmjs.org/package/require-and-forget\n[ci-image]: https://travis-ci.org/bahmutov/require-and-forget.svg?branch=master\n[ci-url]: https://travis-ci.org/bahmutov/require-and-forget\n[semantic-image]: https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg\n[semantic-url]: https://github.com/semantic-release/semantic-release\n[standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg\n[standard-url]: http://standardjs.com/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Frequire-and-forget","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbahmutov%2Frequire-and-forget","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbahmutov%2Frequire-and-forget/lists"}