Skip to content

Commit

Permalink
Maybe this.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Jan 21, 2015
1 parent f4c4929 commit 3a03cfa
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions README.md
Expand Up @@ -46,30 +46,36 @@ Then just require the package in your code:
```javascript
var chokidar = require('chokidar');

var watcher = chokidar.watch('file, dir, or glob', {ignored: /[\/\\]\./, persistent: true});
var watcher = chokidar.watch('file, dir, or glob', {
ignored: /[\/\\]\./, persistent: true
});

var log = console.log.bind(console);

watcher
.on('add', function(path) {console.log('File', path, 'has been added');})
.on('addDir', function(path) {console.log('Directory', path, 'has been added');})
.on('change', function(path) {console.log('File', path, 'has been changed');})
.on('unlink', function(path) {console.log('File', path, 'has been removed');})
.on('unlinkDir', function(path) {console.log('Directory', path, 'has been removed');})
.on('error', function(error) {console.error('Error happened', error);})
.on('ready', function() {console.info('Initial scan complete. Ready for changes.')})
.on('raw', function(event, path, details) {console.info('Raw event info:', event, path, details)})
.on('add', function(path) { log('File', path, 'has been added'); })
.on('addDir', function(path) { log('Directory', path, 'has been added'); })
.on('change', function(path) { log('File', path, 'has been changed'); })
.on('unlink', function(path) { log('File', path, 'has been removed'); })
.on('unlinkDir', function(path) { log('Directory', path, 'has been removed'); })
.on('error', function(error) { log('Error happened', error); })
.on('ready', function() { log('Initial scan complete. Ready for changes.'); })
.on('raw', function(event, path, details) { log('Raw event info:', event, path, details); })

// 'add', 'addDir' and 'change' events also receive stat() results as second
// argument when available: http://nodejs.org/api/fs.html#fs_class_fs_stats
watcher.on('change', function(path, stats) {
if (stats) console.log('File', path, 'changed size to', stats.size);
});

// Watch new files.
watcher.add('new-file');
watcher.add(['new-file-2', 'new-file-3', '**/other-file*']);

// Un-watch some files.
watcher.unwatch('new-file*');

// Only needed if watching is persistent.
// Only needed if watching is `persistent: true`.
watcher.close();

// One-liner
Expand Down

0 comments on commit 3a03cfa

Please sign in to comment.