Codes:
//Node.js v20.9.0, v18.18.2
import { readFile } from "node:fs/promises";
import { load } from "piexifjs";
// ...
if (fileName.match(/\.(jpg|jpeg|png)$/i)) {
console.log(RegExp.$1);
const dataURL = await readFile(filePath, { encoding: "base64" });
const exifObj = load(`data:image/${RegExp.$1};base64,${dataURL}`);
}
// ...
Outputs:
throw new Error("Given file is neither JPEG nor TIFF.");
^
Error: Given file is neither JPEG nor TIFF.
at ExifReader (/xxx/node_modules/.pnpm/piexifjs@2.0.0-beta.9/node_modules/piexifjs/dist/piexif.js:2123:21)
Image:

Codes:
Outputs:
Image: