You don't need to create the middlewear to just check if video exists or not, you simply call the const video=Video.findByIdAndDelete(id); if(!video) res.status(404).json({message:"Video not found"}) and letter the success response comes, this is more better approach