Created
June 21, 2016 15:23
-
-
Save remarkablemark/28f04d4659162c6caffe5c046a52f39c to your computer and use it in GitHub Desktop.
Reload a node module by deleting the cache reference in require.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 'use strict'; | |
| /** | |
| * Re-require a module. | |
| * | |
| * @param {String} path - The module path. | |
| * @return {*} - The module export. | |
| */ | |
| module.exports = function rerequire(path) { | |
| try { | |
| // the path in the cache key must be absolute | |
| // https://nodejs.org/docs/latest/api/globals.html#globals_require_cache | |
| delete require.cache[require.resolve(path)]; | |
| return require(path); | |
| } catch(error) { | |
| throw error; | |
| } | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment