clear-require

Clear a module from the `require` cache

Renamed to `clear-module`.
Last updated 8 years ago by sindresorhus .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install clear-require 
SYNC missed versions from official npm registry.

clear-require Build Status

Clear a module from the require cache

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

Install

$ npm install --save clear-require

Usage

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

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

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

clearRequire('./foo');

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

API

clearRequire(moduleId)

moduleId

Type: string

What you would use with require().

clearRequire.all()

Clear all modules from the require cache.

clearRequire.match(regex)

Clear all matching modules from the require cache.

regex

Type: RegExp

Regex to match against the module ID's.

Related

License

MIT © Sindre Sorhus

Current Tags

  • 3.0.0                                ...           latest (8 years ago)

3 Versions

  • 3.0.0 [deprecated]           ...           8 years ago
  • 2.0.0                                ...           10 years ago
  • 1.0.1                                ...           12 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (2)
Dev Dependencies (2)
Dependents (2)

© 2010 - cnpmjs.org x YWFE | Home | YWFE