You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

4 years ago
  1. # import-fresh [![Build Status](https://travis-ci.org/sindresorhus/import-fresh.svg?branch=master)](https://travis-ci.org/sindresorhus/import-fresh)
  2. > Import a module while bypassing the [cache](https://nodejs.org/api/modules.html#modules_caching)
  3. Useful for testing purposes when you need to freshly import a module.
  4. ## Install
  5. ```
  6. $ npm install --save import-fresh
  7. ```
  8. ## Usage
  9. ```js
  10. // foo.js
  11. let i = 0;
  12. module.exports = () => ++i;
  13. ```
  14. ```js
  15. const importFresh = require('import-fresh');
  16. require('./foo')();
  17. //=> 1
  18. require('./foo')();
  19. //=> 2
  20. importFresh('./foo')();
  21. //=> 1
  22. importFresh('./foo')();
  23. //=> 1
  24. ```
  25. ## Related
  26. - [clear-module](https://github.com/sindresorhus/clear-module) - Clear a module from the import cache
  27. - [import-from](https://github.com/sindresorhus/import-from) - Import a module from a given path
  28. - [import-cwd](https://github.com/sindresorhus/import-cwd) - Import a module from the current working directory
  29. - [import-lazy](https://github.com/sindresorhus/import-lazy) - Import modules lazily
  30. ## License
  31. MIT © [Sindre Sorhus](https://sindresorhus.com)