# decache

> decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.

Latest version **4.6.2** (published 2023-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install decache
pnpm add decache
yarn add decache
bun add decache
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 4.6.2 |
| Published | 2023-06-21 |
| First published | 2015-07-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 10.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 153 |
| Author | https://github.com/dwyl/decache/graphs/contributors |
| Maintainers | nelsonic, luchoturtle |
| Keywords | delete, node.js, require, cache, uncache, un-require |

## Links

- npm: https://www.npmjs.com/package/decache
- Repository: https://github.com/dwyl/decache
- Homepage: https://github.com/dwyl/decache#readme
- Issues: https://github.com/dwyl/decache/issues
- npm.io page: https://npm.io/package/decache

## Dependencies (1)

- [callsite](https://npm.io/package/callsite.md) ^1.0.0

## Alternatives

- [memory-cache](https://npm.io/package/memory-cache.md) — 795.0K weekly downloads
- [@httptoolkit/proxy-agent](https://npm.io/package/@httptoolkit/proxy-agent.md) — 11.2K weekly downloads
- [express-cache-controller](https://npm.io/package/express-cache-controller.md) — 5.3K weekly downloads
- [http-cache-middleware](https://npm.io/package/http-cache-middleware.md) — 4.5K weekly downloads
- [cache2](https://npm.io/package/cache2.md) — 1.5K weekly downloads

## Recent versions

- 4.6.2 (latest) — 2023-06-21
- 4.6.1 — 2021-12-02
- 4.6.0 — 2020-05-12
- 4.5.1 — 2019-01-20
- 4.5.0 — 2018-11-17
- 4.4.1 — 2018-10-26
- 4.4.0 — 2018-02-02
- 4.3.0 — 2017-11-02
- 4.2.0 — 2017-10-20
- 4.1.0 — 2016-08-01
- 4.0.0 — 2016-07-15
- 3.1.0 — 2016-05-22
- 3.0.5 — 2016-03-09
- 3.0.4 — 2016-02-29
- 3.0.3 — 2015-07-21
- … 7 more at https://npm.io/package/decache/versions

## README

# `decache`

Delete a module from node.js' `require.cache` so you can freshly `require` it again.


![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/dwyl/decache/ci.yml?branch=main&label=build&style=flat-square)
[![codecov.io](https://img.shields.io/codecov/c/github/dwyl/decache/main.svg?style=flat-square)](https://codecov.io/github/dwyl/decache?branch=main)
[![dependency status](https://img.shields.io/librariesio/release/npm/decache?style=flat-square)](https://github.com/dwyl/decache/blob/main/package.json#L43)
[![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat-square)](https://github.com/dwyl/decache/issues)
[![HitCount](https://hits.dwyl.com/dwyl/decache.svg)](https://hits.dwyl.com/dwyl/decache)

In node.js when you `require()` a module, node stores a cached version of the
module, so that all subsequent calls to `require()` do not have to reload
the module from the filesystem.

`decache` ( _**De**lete **Cache**_ ) lets you delete modules from node.js `require()` cache
this is useful when _**testing**_ your modules/projects.

## Why?

When testing our modules we often need to re-require the module being tested.
This makes it easy.

## What?

An easy way to delete a cached module.

## How? (_usage_)

### install

Install the module from npm:

```sh
npm install decache --save-dev
```

### Use it in your code:

```js
// require the decache module:
const decache = require('decache');

// require a module that you wrote"
let mymod = require('./mymodule.js');

// use your module the way you need to:
console.log(mymod.count()); // 0   (the initial state for our counter is zero)
console.log(mymod.incrementRunCount()); // 1

// delete the cached module:
decache('./mymodule.js');

//
mymod = require('./mymodule.js'); // fresh start
console.log(mymod.count()); // 0   (back to initial state ... zero)
```

Modules other than `.js`, like for example, `.jsx`, are supported as well.

Note that native modules with the `.node` extension are ignored from decaching because
they behave unexpectedly when decached.

If you have any questions or need more examples, please create a GitHub issue:
https://github.com/dwyl/decache/issues

***Thanks***!

---
_Source: https://npm.io/package/decache · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
