Improve promise/async support for Express 4


I know there is a new and improved Router looming on the horizon for Express 5 (tbd), but it would be nice to see at least basic support for promises/async functions in router handling for current Express (4).


What I’d like to see is a pretty basic, non-breaking change:

  • When the router calls a route handler, if it appears to return a “promise-like” object, attach a catch handler to that object that will call the next(error) function if it is triggered.

This would allow the following two handlers to behave identically:

router.use('/', (req, res) => {
    throw new Error('oops');

router.use('/', async (req, res) => {
    throw new Error('oops');

Author: Fantashit

1 thought on “Improve promise/async support for Express 4

  1. Hi @elliot-nelson ! This has been discussed numerous times, and it was found to be breaking for existing Express 4 apps in the wild, unfortunately, which is why it never landed in Express 4. It has, though, landed in the next router iteration, available for use to test, and in the current Express 5.

    #2259 (comment)

Comments are closed.