Skip to main content
On this page

File system events

Concepts Jump to heading

  • Use Deno.watchFs to watch for file system events.
  • Results may vary between operating systems.

Example Jump to heading

To poll for file system events in the current directory:

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

Run with:

deno run --allow-read watcher.ts

Now try adding, removing and modifying files in the same directory as watcher.ts.

Note that the exact ordering of the events can vary between operating systems. This feature uses different syscalls depending on the platform:

Help us make these docs great!

Did you find what you needed?

Privacy policy

Make a contribution

Deno's docs are open source. See something that's wrong or unclear? Submit a pull request:

Edit this page