Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Express 5 support #14042

Open
1 task done
TrejGun opened this issue Sep 27, 2024 · 0 comments
Open
1 task done

Express 5 support #14042

TrejGun opened this issue Sep 27, 2024 · 0 comments
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@TrejGun
Copy link

TrejGun commented Sep 27, 2024

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

As we are all aware Express 5 has been in beta for a while. I would like to clarify the developers' position on potential migration and define the scope.

Here are the breaking changes introduced in Express.js v5, with additional details and corrections based on the latest documentation:

Route Param Middleware

  • Error Propagation: If next is called with an error in route parameter middleware, it now skips any remaining param middleware and goes straight to error handling, making it more predictable.
app.param('id', (req, res, next, id) => {
  if (isNaN(id)) return next(new Error('ID must be a number'));
  next();
});

app.param('id', (req, res, next, id) => {
  console.log('This will not run if there’s an error in the first handler');
  next();
});

Removed Deprecated Methods

  • Methods like res.sendfile(), res.send(status), and res.json(obj, status) have been removed. Instead, use the camel-cased res.sendFile(), and chain res.status() for setting status codes.
// Old way (v4)
res.json({ message: "success" }, 200);

// New way (v5)
res.status(200).json({ message: "success" });

Improved Error Handling for Async Functions

  • Express 5 automatically forwards errors from async route handlers and middleware to the error-handling middleware. This makes handling errors in asynchronous code much simpler.
// v5 async error handling
app.get('/async-route', async (req, res, next) => {
  throw new Error('This will be caught by the error handler');
});

Changes in Path Route Matching

  • Express 5 introduces stricter route matching rules. For example, wildcard patterns like (*) are no longer valid and must be written as (.*). Additionally, new modifiers like ?, *, and + have been added to parameter patterns.
// Express 4 (Valid)
app.get('/users/:id(\\d+)', (req, res) => { ... });

// Express 5 (Updated syntax)
app.get('/users/:id(\\d+)', (req, res) => { ... });

HTTP/2 Support

Express v5 includes native support for HTTP/2, which allows for better performance and the use of modern features such as multiplexing and server push.

Enforcement of Asynchronous View Rendering

The res.render() method now enforces asynchronous behavior for all view engines, ensuring consistency and avoiding bugs caused by synchronous implementations.

Describe the solution you'd like

native support for express 5 is implemented

Teachability, documentation, adoption, migration strategy

https://expressjs.com/en/guide/migrating-5.html

What is the motivation / use case for changing the behavior?

i would like to utilize new features of ExpressJS 5 like http2 support

@TrejGun TrejGun added needs triage This issue has not been looked into type: enhancement 🐺 labels Sep 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

1 participant