If you need more customization, there is a guide here: https://bun.sh/guides/read-file/watch
For example:
import { watch } from "fs";
const watcher = watch(import.meta.dir, (event, filename) => {
console.log(`Detected ${event} in ${filename}`);
});
process.on("SIGINT", () => {
// close watcher when Ctrl-C is pressed
console.log("Closing watcher...");
watcher.close();
process.exit(0);
});