demo · v133

Recursive directory watcher

Compare {recursive: false} and {recursive: true}. Mutate the tree from this page and watch which events reach you under each mode. The pattern an IDE-style file tree needs.

tree appears here

observer events:

shallow vs deep

An IDE wants every file mutation, no matter how deep; a media gallery probably only cares about top-level images. The recursive option on observe() is per-watch. The same observer can hold many watches with different modes — mix-and-match: deep on src/, shallow on build/.

const obs = new FileSystemObserver(cb);
await obs.observe(root, { recursive: true });
// later:
obs.unobserve(root);

see also