Constructor
new Watcher(optionsopt)
Defines a watcher to be aware of new resources added to one or several directories.
Parameters:
Name | Type | Attributes | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Watcher options Properties
|
- Source:
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'
]);
Members
(readonly) directoriesWatchers :Array
The list of directories' watchers actually running.
Type:
- Array
- Source:
(readonly) options :Object
Watcher options.
Type:
- Object
- Source:
Methods
(private, static) isWatched(directoryPath) → {Boolean}
Checks if a directory is actually being watched.
This:
Parameters:
Name | Type | Description |
---|---|---|
directoryPath |
String | The absolute path of the directory to check |
- Source:
Returns:
true if directory is actually being watched, false otherwise
- Type
- Boolean
add(directoriesPaths, callback)
Adds new directories to watch.
Parameters:
Name | Type | Description |
---|---|---|
directoriesPaths |
Array | The list of absolute directories paths to watch |
callback |
module:watcher/Watcher~Watcher~addCallback | The function to call when directories are being watched |
- Source:
remove(directoriesPathsopt)
Stops watching directories.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
directoriesPaths |
Array |
<optional> |
The list of absolute directories' paths to stop watching. If no directories are specified all watching directories won't be watched anymore |
- Source:
Type Definitions
addCallback(results)
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
results |
Array.<Object> | The list of results Properties
|
- Source: