1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
|
const watcher = chokidar.watch('file, dir, glob, or array', { ignored: /(^|[\/\\])\../, persistent: true });
const log = console.log.bind(console);
watcher .on('add', path => log(`File ${path} has been added`)) .on('change', path => log(`File ${path} has been changed`)) .on('unlink', path => log(`File ${path} has been removed`));
watcher .on('addDir', path => log(`Directory ${path} has been added`)) .on('unlinkDir', path => log(`Directory ${path} has been removed`)) .on('error', error => log(`Watcher error: ${error}`)) .on('ready', () => log('Initial scan complete. Ready for changes')) .on('raw', (event, path, details) => { log('Raw event info:', event, path, details); });
watcher.on('change', (path, stats) => { if (stats) console.log(`File ${path} changed size to ${stats.size}`); });
watcher.add('new-file'); watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);
var watchedPaths = watcher.getWatched();
await watcher.unwatch('new-file*');
watcher.close().then(() => console.log('closed'));
chokidar.watch('file', { persistent: true,
ignored: '*.txt', ignoreInitial: false, followSymlinks: true, cwd: '.', disableGlobbing: false,
usePolling: false, interval: 100, binaryInterval: 300, alwaysStat: false, depth: 99, awaitWriteFinish: { stabilityThreshold: 2000, pollInterval: 100 },
ignorePermissionErrors: false, atomic: true });
|