To prevent resource leaks, you must ensure ExifTool workers are shut down correctly.
Manual Cleanup
For servers or long-running processes, call and await .end() during your application's shutdown procedure (e.g., on SIGINT or SIGTERM).
import { exiftool } from "exiftool-vendored";
async function shutdown(signal) {
try {
await closeApplicationResources();
await exiftool.end();
} finally {
process.kill(process.pid, signal);
}
}
process.once("SIGINT", (signal) => void shutdown(signal));
process.once("SIGTERM", (signal) => void shutdown(signal));
Automatic Cleanup (TypeScript 5.2+)
If using TypeScript 5.2+ with explicit resource management, you can use using or await using to bind the instance lifecycle to a scope.
import { ExifTool } from "exiftool-vendored";
// Starts cleanup when the scope exits, but does not wait for it
{
using et = new ExifTool();
const tags = await et.read("photo.jpg");
}
// Waits for asynchronous cleanup when the scope exits (recommended)
{
await using et = new ExifTool();
const tags = await et.read("photo.jpg");
}
import { exiftool } from "exiftool-vendored";
async function shutdown(signal) {
try {
await closeApplicationResources(); // Server, sockets, database, etc.
await exiftool.end();
} finally {
// A signal listener disables Node's default termination behavior. Re-send
// the signal after cleanup so the process terminates normally.
process.kill(process.pid, signal);
}
}
process.once("SIGINT", (signal) => void shutdown(signal));
process.once("SIGTERM", (signal) => void shutdown(signal));