@@ -109,14 +109,19 @@ non-UTF-8 encoded Buffers to `fs` functions will not work as expected.
109109added: v0.5.8
110110-->
111111
112- Objects returned from ` fs.watch() ` are of this type.
112+ Objects returned from [ ` fs.watch() ` ] [ ] are of this type.
113+
114+ The ` listener ` callback provided to ` fs.watch() ` receives the returned FSWatcher's
115+ ` change ` events.
116+
117+ The object itself emits these events:
113118
114119### Event: 'change'
115120<!-- YAML
116121added: v0.5.8
117122-->
118123
119- * ` event ` {String} The type of fs change
124+ * ` eventType ` {String} The type of fs change
120125* ` filename ` {String | Buffer} The filename that changed (if relevant/available)
121126
122127Emitted when something changes in a watched directory or file.
@@ -128,7 +133,8 @@ support. If `filename` is provided, it will be provided as a `Buffer` if
128133` filename ` will be a string.
129134
130135``` js
131- fs .watch (' ./tmp' , {encoding: ' buffer' }, (event , filename ) => {
136+ // Example when handled through fs.watch listener
137+ fs .watch (' ./tmp' , {encoding: ' buffer' }, (eventType , filename ) => {
132138 if (filename)
133139 console .log (filename);
134140 // Prints: <Buffer ...>
@@ -1443,10 +1449,13 @@ directory. The returned object is a [`fs.FSWatcher`][].
14431449The second argument is optional. If ` options ` is provided as a string, it
14441450specifies the ` encoding ` . Otherwise ` options ` should be passed as an object.
14451451
1446- The listener callback gets two arguments ` (event , filename) ` . ` event ` is either
1452+ The listener callback gets two arguments ` (eventType , filename) ` . ` eventType ` is either
14471453` 'rename' ` or ` 'change' ` , and ` filename ` is the name of the file which triggered
14481454the event.
14491455
1456+ Please note the listener callback is attached to the ` 'change' ` event
1457+ fired by [ ` fs.FSWatcher ` ] [ ] , but they are not the same thing.
1458+
14501459### Caveats
14511460
14521461<!-- type=misc-->
@@ -1499,8 +1508,8 @@ be provided. Therefore, don't assume that `filename` argument is always
14991508provided in the callback, and have some fallback logic if it is null.
15001509
15011510``` js
1502- fs .watch (' somedir' , (event , filename ) => {
1503- console .log (` event is: ${ event } ` );
1511+ fs .watch (' somedir' , (eventType , filename ) => {
1512+ console .log (` event type is: ${ eventType } ` );
15041513 if (filename) {
15051514 console .log (` filename provided: ${ filename} ` );
15061515 } else {
0 commit comments