Skip to content
/ sane Public
forked from amasad/sane

sane aims to be fast, small, and reliable filesystem watcher. No bells and whistles, just change events.

Notifications You must be signed in to change notification settings

pandell/sane

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

69 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sane

I've been driven to insanity by node filesystem watcher wrappers. Sane aims to be fast, small, and reliable file system watcher. It does that by:

  • Always use fs.watch (unless polling is forced) and sensibly workaround the various issues with it
  • Sane is all JavaScript, no native components
  • Stay away from polling because it's very slow and cpu intensive
  • Support polling for environments like Vagrant shared directory where there are no native filesystem events

Install

$ npm install sane

If you're using node < v0.10.0 then make sure to start sane with poll: true.

API

sane(dir, globs, options)

Watches a directory and all it's descendant directorys for changes, deletions, and additions on files and directories. Shortcut for new sane.Watcher(dir, {glob: globs, ..options}).

var watcher = sane('path/to/dir', ['**/*.js', '**/*.css']);
watcher.on('ready', function () { console.log('ready') });
watcher.on('change', function (filepath, root, stat) { console.log('file changed', filepath); });
watcher.on('add', function (filepath, root, stat) { console.log('file added', filepath); });
watcher.on('delete', function (filepath, root) { console.log('file deleted', filepath); });
// close
watcher.close();

For options see sane.Watcher.

sane.Watcher(dir, options)

options:

  • persistent: boolean indicating that the process shouldn't die while we're watching files.
  • glob: a single string glob pattern or an array of them.
  • poll: puts the watcher in polling mode. Under the hood that means fs.watchFile.
  • interval: indicates how often the files should be polled. (passed to fs.watchFile)

For the glob pattern documentation, see minimatch.

sane.Watcher#close

Stops watching.

sane.Watcher events

Emits the following events:

All events are passed the file/dir path relative to the root directory

  • ready when the program is ready to detect events in the directory
  • change when a file changes
  • add when a file or directory has been added
  • delete when a file or directory has been deleted

License

MIT

About

sane aims to be fast, small, and reliable filesystem watcher. No bells and whistles, just change events.

Resources

Stars

Watchers

Forks

Packages

No packages published