Skip to content
Newer
Older
100644 84 lines (61 sloc) 3.04 KB
458512d @paulmillr Add files.
authored Apr 20, 2012
1 # Chokidar
2 A neat wrapper around node.js fs.watch / fs.watchFile.
3
4 ## Why?
5 Node.js `fs.watch`:
6
0b67c45 @paulmillr Update readme.
authored May 4, 2012
7 * Doesn't report filenames on mac.
8 * Doesn't report events at all when using editors like TextMate2 on mac.
9 * Sometimes report events twice.
10 * Has only one non-useful event: `rename`.
458512d @paulmillr Add files.
authored Apr 20, 2012
11 * Has [a lot of other issues](https://github.com/joyent/node/issues/search?utf8=✓&q=fs.watch)
12
13 Node.js `fs.watchFile`:
14
15 * Doesn't work on windows
16 * Almost as shitty in event tracking.
17
18 Chokidar resolves this problems.
19
20 It is used in [brunch](http://brunch.io) and had proven itself in production env.
21
22 ## Getting started
23 Install chokidar via node.js package manager:
24
25 npm install chokidar
26
27 Then just require the package in your code:
28
29 ```javascript
30 var chokidar = require('chokidar');
31
7cf6098 @paulmillr Add persistent option to example code.
authored Jun 8, 2012
32 var watcher = chokidar.watch('file or dir', {ignored: /^\./, persistent: true});
458512d @paulmillr Add files.
authored Apr 20, 2012
33
34 watcher
35 .on('add', function(path) {console.log('File', path, 'has been added');})
36 .on('change', function(path) {console.log('File', path, 'has been changed');})
37 .on('unlink', function(path) {console.log('File', path, 'has been removed');})
38 .on('error', function(error) {console.error('Error happened', error);})
3cbf2b1 @paulmillr Release 0.2.1.
authored May 4, 2012
39
40 watcher.add('new-file');
41 watcher.add(['new-file-2', 'new-file-3']);
42
43 // Only needed if watching is persistent.
44 watcher.close();
458512d @paulmillr Add files.
authored Apr 20, 2012
45 ```
46
e85ab9e @paulmillr Add options.persistent.
authored Apr 26, 2012
47 ## API
48 * `chokidar.watch(paths, options)`: takes paths to be watched and options:
49 * `options.ignored` (regexp or function) files to be ignored. Example:
50 `chokidar.watch('file', {ignored: /^\./})`.
0b67c45 @paulmillr Update readme.
authored May 4, 2012
51 * `options.persistent` (default: `false`). indicates whether the process
e85ab9e @paulmillr Add options.persistent.
authored Apr 26, 2012
52 should continue to run as long as files are being watched.
53
54 `chokidar.watch()` produces an instance of `FSWatcher`. Methods of `FSWatcher`:
55
458512d @paulmillr Add files.
authored Apr 20, 2012
56 * `.add(file / files)`: add directories / files for tracking.
57 Takes an array of strings (file paths) or just one path.
58 * `.on(event, callback)`: listen for an FS event.
59 Available events: add, change, unlink, error.
60 * `.close()`: remove all listeners from watched files.
61
62 ## License
63 The MIT license.
64
2fccccd @paulmillr Release 0.2.4.
authored Jun 7, 2012
65 Copyright (c) 2012 Paul Miller (http://paulmillr.com)
458512d @paulmillr Add files.
authored Apr 20, 2012
66
67 Permission is hereby granted, free of charge, to any person obtaining a copy of
68 this software and associated documentation files (the "Software"), to deal in
69 the Software without restriction, including without limitation the rights to
70 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
71 of the Software, and to permit persons to whom the Software is furnished to do
72 so, subject to the following conditions:
73
74 The above copyright notice and this permission notice shall be included in all
75 copies or substantial portions of the Software.
76
77 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
78 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
80 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
81 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
82 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
83 SOFTWARE.
Something went wrong with that request. Please try again.