Hi

Delete a file in Node.js

 const fs = require("fs/promises");

const path = require("path");


const filePath = path.join(thumbDir, fileName);


try {

  await fs.unlink(filePath);

  console.log("File deleted successfully");

} catch (err) {

  if (err.code === "ENOENT") {

    console.log("File not found, nothing to delete");

  } else {

    throw err;

  }

}


Latest
Previous
Next Post »