folder-watcher
v1.0.0
Published
File system watcher, event organizer.
Downloads
1
Maintainers
Readme
folder-Watcher
Using the folder-watcher module is very simple, you should take into consideration that this module is used to observe the elements within the selected folder.
You should know, that the best way to monitor a file is to monitor its container.
How to use
//declare module
const folderWatcher = require('folder-watcher');
//wathcher folder
folderWatcher.on('Your folder path here' [, options], (object) => {
//handle event
if (object.event === 'move' || object.event === 'rename') {
console.log(`event : ${object.event} from ${object.file} to ${object.to}`);
}
else {
// create, delete or change
console.log(`event : ${object.event} in file ${object.file}`);
};
});
Parameters
- path => String => Obligatory => Folder path only.
- options => Object => optional => Default { persistent : true, recursive: true, encoding: utf-8 }.
- calback => Function => Obligatory => Returns an event along with its respective paths.
Returns
The returned object can contain 3 elements, event, file, to.
- event => create, delete, move, rename, change.
- file => path of the file that has been modified.
- to => in case of events move and rename revolve the path of change.
Examples Returns
object = {
event: 'create',
from: './your/path/file.ext'
}
object: {
event: 'delete',
from: './file/path/delete.ext'
}
object: {
event: 'change',
from: './file/path/change.ext'
}
object: {
event: 'rename',
from: './yout/path/file.ext',
to: './your/path/renamefile.ext'
}
object: {
event: 'move',
from: './yout/path/file.ext',
to: './your/new/path/file.ext'
}