File system watcher, event organizer.
npm install folder-watcher
js
//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
1. path => String => Obligatory => Folder path only.
2. options => Object => optional => Default { persistent : true, recursive: true, encoding: utf-8 }.
3. 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
`js
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'
}
``