blob: f5414b8cf33fdd46bf238b9c7605d1e73889bd47 [file] [log] [blame] [view]
Kaido Kertf585e262020-06-08 11:42:28 -07001# import-fresh [![Build Status](https://travis-ci.org/sindresorhus/import-fresh.svg?branch=master)](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
5Useful 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
19let i = 0;
20module.exports = () => ++i;
21```
22
23```js
24const importFresh = require('import-fresh');
25
26require('./foo')();
27//=> 1
28
29require('./foo')();
30//=> 2
31
32importFresh('./foo')();
33//=> 1
34
35importFresh('./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>