fs.unlink(path, callback)


异步删除文件或符号链接。完成回调函数不会接收任何参数,除了可能的异常。

【Asynchronously removes a file or symbolic link. No arguments other than a possible exception are given to the completion callback.】

import { unlink } from 'node:fs';
// Assuming that 'path/file.txt' is a regular file.
unlink('path/file.txt', (err) => {
  if (err) throw err;
  console.log('path/file.txt was deleted');
}); 

fs.unlink() 无法用于目录,无论是否为空。要删除目录,请使用 fs.rmdir()

有关更多详细信息,请参阅 POSIX unlink(2) 文档。

【See the POSIX unlink(2) documentation for more details.】