pit-require-cache is a zero-configuration watcher that deletes require's
cache for any updated file.
Lets say that you are importing trought require a specific file and then serving that file trought a express server, then you update that file and as require
cache the files already imported you need to stop the server and start it again.
With pit-require-cache
is not needed anymore, just instantiate the watcher once and then it will delete the cache for you making the changes appear all straight.
npm install pit-require-cache
const { watcher } = require('pit-require-cache')
watcher()
const options = {
persistent: true,
ignored: '*.txt',
ignoreInitial: false,
followSymlinks: true,
cwd: '.',
disableGlobbing: false,
usePolling: true,
interval: 100,
binaryInterval: 300,
alwaysStat: false,
depth: 99,
awaitWriteFinish: {
stabilityThreshold: 2000,
pollInterval: 100
},
ignorePermissionErrors: false,
atomic: true
}
watcher({directory: 'myFolderName', ...options})
{
directory Directory to be watched [default: ".", string or array of strings]
options: { Options object [default: {}, object]
persistent Show version number [default: true, boolean]
ignored Ignored files [default: '', string, example: '*.txt']
ignoreInitial Add/addDir events are also [default: false, boolean]
emitted while instantiating
followSymlinks Watch followinf symbolic links [default: true, boolean]
cwd Base directory [default: '.', string]
usePolling Whether to use fs.watchFile or [default: false, boolean]
fs.watchtrue
interval Interval for polling [default: 100, number]
binaryInterval Interval polling for binary files.[default: 300, number]
depth Limits how many levels of
subdirectories will be traversed. [default: undefined, number]
awaitWriteFinish Wait until the size of the file [default: undefined, example: {
stays constant. stabilityThreshold: 2000,
pollInterval: 100
}, object]
ignorePermissionErrors Silence the access errors [default: false, boolean]
}
}
As we are using chokidar
module for the watcher implementation, there are a couple more options that can be checked on chokidar
's module docs https://www.npmjs.com/package/chokidar/v/2.0.4