若要使用 Bun 同步刪除檔案,請使用 node:fs
模組中的 unlinkSync
函式。(目前,Bun
API 沒有用於刪除檔案的功能。)
import { unlinkSync } from "node:fs";
const path = "/path/to/file.txt";
unlinkSync(path);
若要非同步移除檔案,請使用 node:fs/promises
模組中的 unlink
函式。
import { unlink } from "node:fs/promises";
const path = "/path/to/file.txt";
await unlink(path);