1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-23 15:16:54 -05:00
denoland-deno/docs/examples/file_system_events.md
2020-09-12 08:03:18 -04:00

1.1 KiB

File system events

Concepts

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

Example

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: