Sign In

clear-module

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

clear-module

Clear a module from the cache

Source
npmnpm
Version
4.1.1
Version published
Weekly downloads
793K
-17.24%
Maintainers
1
Weekly downloads
 
Created
Source

clear-module Build Status

Clear a module from the cache

Useful for testing purposes when you need to freshly import a module.

Install

$ npm install clear-module

Usage

// foo.js
let i = 0;
module.exports = () => ++i;
const clearModule = require('clear-module');

require('./foo')();
//=> 1

require('./foo')();
//=> 2

clearModule('./foo');

require('./foo')();
//=> 1

API

clearModule(moduleId)

moduleId

Type: string

What you would use with require().

clearModule.all()

Clear all modules from the cache.

clearModule.match(regex)

Clear all matching modules from the cache.

regex

Type: RegExp

Regex to match against the module IDs.

clearModule.single(moduleId)

Clear a single module from the cache non-recursively. No parent or children modules will be affected.

This is mostly only useful if you use singletons, where you would want to clear a specific module without causing any side effects.

moduleId

Type: string

What you would use with require().

  • import-fresh - Import a module while bypassing the cache
  • import-from - Import a module from a given path
  • import-cwd - Import a module from the current working directory
  • import-lazy - Import a module lazily

Keywords

clear

FAQs

Package last updated on 09 Mar 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts