Watcher
Summary
Defines a watcher to be aware of new resources added to one or several directories.
Constructor
Watcher
Syntax
Watcher
-
[options]
Summary
Parameters:
Example:
// Create a new watcher
var watcher = new Watcher();
// Listen to watcher events
watcher.on('create', function(resourcePath) {
console.log('A new file has been added : ' + resourcePath);
});
watcher.on('delete', function(resourcePath) {
console.log('A file has been removed : ' + resourcePath);
});
watcher.on('watch', function(directoryPath) {
console.log('A watcher is now running for directory ' + directoryPath);
});
watcher.on('error', function(error) {
console.log(error);
});
// Ask watcher to watch directories
watcher.add([
'/tmp/hotFolder1',
'/tmp/hotFolder2',
'/tmp/hotFolder3'
], function(results) {
console.log(results);
});
// Ask watcher to stop watching directories
watcher.remove([
'/tmp/hotFolder3'
]);
Item Index
Properties
Methods
add
Syntax
add
-
directoriesPaths
-
callback
Summary
Adds new directories to watch.
isWatched
Syntax
Summary
Checks if a directory is actually being watched.
Parameters:
-
directoryPath
StringThe absolute path of the directory to check
Returns:
true if directory is actually being watched, false otherwise
remove
Syntax
remove
-
[directoriesPaths]
Summary
Stops watching directories.
Parameters:
-
[directoriesPaths]
Array optionalThe list of absolute directories' paths to stop watching. If no directories are specified all watching directories won't be watched anymore
Properties
directoriesWatchers
Syntax
Summary
The list of directories' watchers actually running.
Events
create
Syntax
create
Summary
Fired when a new resource (file or directory) has been added to one of the watched folders.
Event Payload:
-
Path
Stringof the added resource
delete
Syntax
delete
Summary
Fired when a resource (file or directory) has been deleted from one of the watched folders.
Event Payload:
-
Path
Stringof the resource before it has been removed
watch
Syntax
watch
Summary
Fired when a directory is added to watched directories.
Fired after "create" event in case the directory is added to an already watched directory.
Event Payload:
-
Path
Stringof the directory