UNPKG

1.93 kBMarkdownView Raw
1# decache
2
3[![Build Status](https://travis-ci.org/dwyl/decache.svg)](https://travis-ci.org/dwyl/decache)
4[![codecov.io](https://codecov.io/github/dwyl/decache/coverage.svg?branch=master)](https://codecov.io/github/dwyl/decache?branch=master)
5[![Code Climate](https://codeclimate.com/github/dwyl/decache/badges/gpa.svg)](https://codeclimate.com/github/dwyl/decache)
6[![Dependency Status](https://david-dm.org/dwyl/decache.svg)](https://david-dm.org/dwyl/decache)
7[![devDependency Status](https://david-dm.org/dwyl/decache/dev-status.svg)](https://david-dm.org/dwyl/decache#info=devDependencies)
8
9In node.js when you `require()` a module, node stores a cached version of the
10module, so that all subsequent calls to `require()` do not have to reload
11the module from the filesystem.
12
13`decache` ( _**De**lete **Cache**_ ) lets you delete modules from node.js `require()` cache
14this is useful when _**testing**_ your modules/projects.
15
16## Why?
17
18When testing our modules we often need to re-require the module being tested.
19This makes it easy.
20
21## What?
22
23An easy way to delete a cached module.
24
25## How? (_usage_)
26
27### install
28
29Install the module from npm:
30
31```sh
32npm install decache --save-dev
33```
34
35### Use it in your code:
36
37```js
38// require the decache module:
39var decache = require('decache');
40
41// require a module that you wrote"
42var mymod = require('./mymodule.js');
43
44// use your module the way you need to:
45console.log(mymod.count()); // 0 (the initial state for our counter is zero)
46console.log(mymod.incrementRunCount()); // 1
47
48// delete the cached module:
49decache('./mymodule.js');
50
51//
52mymod = require('./mymodule.js'); // fresh start
53console.log(mymod.count()); // 0 (back to initial state ... zero)
54```
55
56Modules other than `.js`, like for example, `.jsx`, are supported as well.
57
58If you have any questions or need more examples, please create a GitHub issue:
59https://github.com/nelsonic/decache/issues
60
61***Thanks***!