---
title: "Discussion on \"Optimizing Express Middleware: Passing Data via req to Avoid Extra DB Queries\" | Hashnode"
description: "Discussion on \"Optimizing Express Middleware: Passing Data via req to Avoid Extra DB Queries\". Background\nso i am currently working on a youtube clone backend project which i started to understand backend development and express better. i have had made the architecture in the standard form like controller in one directory , models in one direc..."
url: "https://hashnode.com/posts/optimizing-express-middleware-passing-data-via-req-to-avoid-extra-db-queries/6835eb2a07b1990086c5e7bc"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [Optimizing Express Middleware: Passing Data via req to Avoid Extra DB Queries](https://nodejs-backend-tips.hashnode.dev/optimizing-express-middleware-passing-data-via-req-to-avoid-extra-db-queries?utm_source=hashnode&utm_medium=feed)

Background so i am currently working on a youtube clone backend project which i started to understand backend development and express better. i have had made the architecture in the standard form like controller in one directory , models in one direc...

May 27, 2025 · 2 min read · nodejs-backend-tips.hashnode.dev  
Read the article

-   [#middleware-optimization](https://hashnode.com/tag/middleware-optimization)
-   [#express](https://hashnode.com/tag/express)
-   [#expressjs-cilb5apda0066e053g7td7q24](https://hashnode.com/tag/expressjs-cilb5apda0066e053g7td7q24)
-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#nodejs-backend-development](https://hashnode.com/tag/nodejs-backend-development)
-   [#nodejs-best-practices](https://hashnode.com/tag/nodejs-best-practices)
-   [#api-design-best-practices](https://hashnode.com/tag/api-design-best-practices)
-   [#api-design](https://hashnode.com/tag/api-design)

## Written by

[Mohammad Afnan](https://hashnode.com/@afnan2208)

@afnan2208

  
[View profile](https://hashnode.com/@afnan2208)

developer and tech enthusiast

## Responses 1

Markdown supported · ⌘↵ to post

[Mohammed Arafat](https://hashnode.com/@MohammedArafat)

[Jun 3, 2025](https://hashnode.com/posts/optimizing-express-middleware-passing-data-via-req-to-avoid-extra-db-queries/6835eb2a07b1990086c5e7bc/comment/683f2e0f007d12c244379c67)

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
