Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/deno/cli/tsc/dts/lib.deno.ns.d.ts>Deno.watchFs

A modern runtime for JavaScript and TypeScript.
Go to Latest
function Deno.watchFs
allow-read
import { Deno } from "https://deno.land/x/deno@v1.28.3/cli/tsc/dts/lib.deno.ns.d.ts";
const { watchFs } = Deno;

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[]
optional
options: { recursive: boolean; }