← Back to index
function Deno.watchFs

Watch for file system events against one or more paths, which can be files or directories. These paths must exist already. One user action (e.g. touch test.file) can generate multiple file system events. Likewise, one user action can result in multiple file paths in one event (e.g. mv old_name.txt new_name.txt).

The recursive option is true by default and, for directories, will watch the specified directory and all sub directories.

Note that the exact ordering of the events can vary between operating systems.

const watcher = Deno.watchFs("/");
for await (const event of watcher) {
   console.log(">>>> event", event);
   // { kind: "create", paths: [ "/foo.txt" ] }
}

Call watcher.close() to stop watching.

const watcher = Deno.watchFs("/");

setTimeout(() => {
  watcher.close();
}, 5000);

for await (const event of watcher) {
   console.log(">>>> event", event);
}

Requires allow-read permission.

Parameters

🔗
paths: string | string[]
🔗
options: { recursive: boolean; }