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
2.1.0
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 --save 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.

  • 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

License

MIT © Sindre Sorhus

Keywords

clear

FAQs

Package last updated on 21 May 2017

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