0.3.1 • Published 10 years ago
watch-sync v0.3.1
watch-sync
Watch for file changes and replicate them to a new location.
Performs initial synchronization between the src and dest directories and then sets a watcher that updates the dest directory any time a change is made.
Getting Started
Install watch-sync via NPM:
npm install watch-syncThen require it to use it:
var watchSync = require("watch-sync");
var srcDir = ".";
var destDir = "/tmp/watchSync";
var options = {};
var watcher = watchSync(srcDir, destDir, options);
watcher.on("ready", function() { console.log("ready"); });
watcher.on("add", function(filepath, destDir, stat) {
console.log("File / directory added", filepath, "in", destDir);
});
watcher.on("change", function(filepath, destDir, stat) {
console.log("File / directory changed", filepath, "in", destDir);
});
watcher.on("delete", function(filepath, destDir) {
console.log("File / directory removed", filepath, "from", destDir);
});By default watchSync is persistent, which means it will run even after the
initial sync. You can close the watcher with watcher.close().
API
watchSync(srcDir, destDir, [options])
srcDiris the source directory to watch.destDiris the path to the destination directory. The directory will be created if it does not already exist.optionsis an optional set of configuration entries, as described in the Options section below.
Options
persistent(default:true). Iftruecontinue to watch the srcDir for changes after the initial sync. To close a persistent watcher usewatcher.close().delete(default:true). Whentruea delete of a file insrcDirafter thereadyevent will cause the associated file indestDirto be removed.preserveTimestamps(default:false). If enabled sets the modified time of synchronized files to the modified time of the source file.
Events
readyis fired after the initial sync of the file system.addis fired when a file or directory is added. This is only fired afterready.changeis fired when a file or directory is changed. This is only fired afterready.deleteis fired when a file or directory is removed. This is only fired afterready.
watchSync.version()
Returns the version of the watchSync library.