A tiny wrapper around fs.watch for added, removed and changed events
There is no such thing as fs.watch and this is a wrapper around it. Another one. Yep, there are lots of wrappers and I tried a couple for my project but found that they were all buggy in their own idiosyncratic ways. I needed one that was buggy in a specific way, so I coded up tiny-wrapper.
var tiny = require'../.'fs = require'fs'rimraf = require'rimraf'path = require'path'var somedir = "somedir"fsmkdirSyncsomedirvar watcher = tinysomedir "test" "total"watcheron"added"console.log"EXAMPLE: added" filewatcheron"removed"console.log"EXAMPLE: removed" filewatcheron"changed"console.log"EXAMPLE: changed" file// ADD TESTfswriteFileSyncpathjoinsomedir "test" "data"// REMOVE TESTfsunlinkSyncpathjoinsomedir "test"// ADD TOTALfswriteFileSyncpathjoinsomedir "total" "data"// CHANGE TOTALfswriteFileSyncpathjoinsomedir "total" "new data"// ADD TONNES (NOT IN SPECIFIED FILE LIST)fswriteFileSyncpathjoinsomedir "tonnes" "data"/** Setting watcher kill should stop the remove event* when total is removed with rimraf*/setTimeoutwatchercloserimrafsomedirif err throw errprocessexit1000
EXAMPLE: added testEXAMPLE: removed testEXAMPLE: added totalEXAMPLE: changed totalEXAMPLE: added testEXAMPLE: removed test
The main object is a function that produces watchers for a specific directory an optional set of files.
var watcher = tiny"path/to/dir" "list" "of" "files"
changed are supported. The callback returns the filename.
Calls the base fs method watcher.close()
npm install tiny-watcher