Kaido Kert | f585e26 | 2020-06-08 11:42:28 -0700 | [diff] [blame] | 1 | # import-fresh [](https://travis-ci.org/sindresorhus/import-fresh) |
| 2 | |
| 3 | > Import a module while bypassing the [cache](https://nodejs.org/api/modules.html#modules_caching) |
| 4 | |
| 5 | Useful for testing purposes when you need to freshly import a module. |
| 6 | |
| 7 | |
| 8 | ## Install |
| 9 | |
| 10 | ``` |
| 11 | $ npm install import-fresh |
| 12 | ``` |
| 13 | |
| 14 | |
| 15 | ## Usage |
| 16 | |
| 17 | ```js |
| 18 | // foo.js |
| 19 | let i = 0; |
| 20 | module.exports = () => ++i; |
| 21 | ``` |
| 22 | |
| 23 | ```js |
| 24 | const importFresh = require('import-fresh'); |
| 25 | |
| 26 | require('./foo')(); |
| 27 | //=> 1 |
| 28 | |
| 29 | require('./foo')(); |
| 30 | //=> 2 |
| 31 | |
| 32 | importFresh('./foo')(); |
| 33 | //=> 1 |
| 34 | |
| 35 | importFresh('./foo')(); |
| 36 | //=> 1 |
| 37 | ``` |
| 38 | |
| 39 | |
| 40 | ## Related |
| 41 | |
| 42 | - [clear-module](https://github.com/sindresorhus/clear-module) - Clear a module from the import cache |
| 43 | - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path |
| 44 | - [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory |
| 45 | - [import-lazy](https://github.com/sindresorhus/import-lazy) - Import modules lazily |
| 46 | |
| 47 | |
| 48 | --- |
| 49 | |
| 50 | <div align="center"> |
| 51 | <b> |
| 52 | <a href="https://tidelift.com/subscription/pkg/npm-require-uncached?utm_source=npm-require-uncached&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> |
| 53 | </b> |
| 54 | <br> |
| 55 | <sub> |
| 56 | Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. |
| 57 | </sub> |
| 58 | </div> |