1. decache
decache (Delete Cache) lets you delete modules from node.js require() cache; useful when testing your modules/projects.
decache
Package: decache
Created by: dwyl
Last modified: Wed, 21 Jun 2023 10:26:02 GMT
Version: 4.6.2
License: MIT
Downloads: 4,518,491
Repository: https://github.com/dwyl/decache

Install

npm install decache
yarn add decache

decache

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

GitHub Workflow Status
codecov.io
dependency status
contributions welcome
HitCount

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 ( Delete 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:

 npm install decache --save-dev

Use it in your code:

 // 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!

Dependencies

RELATED POST

10 Must-Know Windows Shortcuts That Will Save You Time

10 Must-Know Windows Shortcuts That Will Save You Time

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Arrays vs Linked Lists: Which is Better for Memory Management in Data Structures?

Navigating AWS Networking: Essential Hacks for Smooth Operation

Navigating AWS Networking: Essential Hacks for Smooth Operation

Achieving Stunning Visuals with Unity's Global Illumination

Achieving Stunning Visuals with Unity's Global Illumination

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code

Nim's Hidden Gems: Lesser-known Features for Writing Efficient Code