Express.js middleware to clean up uploaded files after multer
import express from 'express';
import { cleanUploadedFilesMiddleware } from '@myrotvorets/clean-up-after-multer'
const app = express();
app.use(/* your middlewares here */);
app.use(cleanUploadedFilesMiddleware());
Make sure to call next()
from your middlewares.
cleanUploadedFilesMiddleware()
accepts an argument of type (path: string) => Promise<unknown>
to specify the custom unlink()
function (in case you want to log unlink failures etc).