Skip to content

viniciusdiogo/simple-watcher

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Watcher

A simple recursive directory watcher.

But why?

I know there's plenty of them out there, but most don't seem to care about the recursive option of Node's fs.watch(), which significantly improves performance on the supported platforms, especially for large directories.

Features:

  • Dead simple and dead lightweight.
  • No dependencies.
  • Leverages the recursive options on OS X and Windows; uses a fallback for other platforms.
  • Takes care of WinAPI's ReadDirectoryChangesW double reporting.

Usage

const watch = require('simple-watcher')

/**
 * Recursively watches for directory changes.
 * @param {string} workingDir - Directory to watch.
 * @param {function} callback - Triggered on change.
 * @param {number} tolerance - Interval in which multiple changes to the same file
 *                             on Windows will be treated as one; default is 200ms.
 */
watch('/path/to/directory', (filePath) => {
  console.log(`Changed: ${filePath}`)
})

About

A simple recursive directory watcher.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%