Skip to content

Conversation

@ViKing-Coder-jpg
Copy link

PR: Comprehensive Middleware Guide and Deep Dive Examples

#Overview
This PR introduces a detailed Middleware Guide and corresponding interactive examples for Express.js. It provides developers with a deeper understanding of middleware execution order, error handling, async patterns, and best practices, addressing gaps in existing documentation.


New Files Created

1.examples/middleware-deep-dive/index.js`** – Interactive example demonstrating:

  • Correct middleware execution order
  • Async error handling
  • Side-by-side comparisons of correct vs incorrect patterns
  • Console output to visualize middleware flow

This PR enhances Express.js documentation by providing a comprehensive middleware guide with interactive examples, covering execution order, error handling, and async patterns. It directly addresses developer pain points and improves learning resources.

Fixes: expressjs/expressjs.com#2157

@socket-security
Copy link

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedexpress@​5.1.09810010086100

View full report

Copy link
Contributor

@krzysdz krzysdz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR introduces a detailed Middleware Guide and corresponding interactive examples

I can only see a single example. There are guides related to middleware on the Express.js website (expressjs/expressjs.com), but I don't see any PRs from you there. Did you forget to add something here or open a PR in the website repo?

  • Side-by-side comparisons of correct vs incorrect patterns

I can't see this anywhere either.

"encodeurl": "^2.0.0",
"escape-html": "^1.0.3",
"etag": "^1.8.1",
"express": "^5.1.0",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why should express have itself as a dependency?

Comment on lines +46 to +51
function userHandler(req, res, next) {
console.log('3. Route Handler: Executing');
res.send(`User ID: ${req.params.id}, Requested at: ${req.requestTime}`);
console.log('3. Route Handler: Finished (response sent)');
// Note: We don't call next() here because we sent a response.
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you are not using next() it can be omitted from the function signature. The only case when Express cares about the number of arguments in function signature is error handlers (must have exactly 4).

@krzysdz
Copy link
Contributor

krzysdz commented Jan 19, 2026

I'm closing this, since the PR description and code do not match. Current examples show most of what you want to achieve. If you notice something missing in documentation and guides, please open issues in the website repository - expressjs/expressjs.com.

If you are using AI-powered tools, please check the output and verify that it makes sense.

@krzysdz krzysdz closed this Jan 19, 2026
@expressjs expressjs locked as spam and limited conversation to collaborators Jan 19, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants