node:fs
module, including the fs.watch
function for listening for file system changes.
This code block listens for changes to files in the current directory. By default this operation is shallow, meaning that changes to files in subdirectories will not be detected.
To listen to changes in subdirectories, pass the
recursive: true
option to fs.watch
.
Using the
node:fs/promises
module, you can listen for changes using for await...of
instead of a callback.
To stop listening for changes, call
watcher.close()
. It’s common to do this when the process receives a SIGINT
signal, such as when the user presses Ctrl-C.
Refer to API > Binary data > Typed arrays for more information on working with
Uint8Array
and other binary data formats in Bun.