Hacker News new | ask | show | jobs
by rrishi 773 days ago
Where does this version of express put it against its competitors (Koa, Fastify, Hono etc)?
2 comments

Koa hasn't really been a thing since async/await came to JS and addressed most if not all of the pain points in Express that Koa initially was created to alleviate (the pyramid of doom being the main one).

It seems like there is still occasional work there, but it seems more like bare minimum bugfixes and docs improvements. I've maybe seen one company using Koa in the last 5 years.

Fastify would be the closest modern framework, but it's a significant departure from both Express and Koa, taking the convention over configuration approach, but it's not batteries-included.

What are you talking about WRT Koa? Express 4 does not support async/await natively in its middleware. That means if your async method throws an error, you need to catch it and return it yourself or else it will just crash the app. That's one reason why I currently use Koa. Express 5 finally supports async/await and it is only now being officially released.
You can fix async await with express by just installing a package.
Which package?
This one does it via monkey patching express internals to make the fix transparent: https://www.npmjs.com/package/express-async-errors
That still doesn't address the main difference between Express and Koa.

In Express, the route handlers send the response directly so your middleware can only be "beforeware".

In Koa, the route handlers update a response object that bubbles back up the stack before it's sent, so you can write both beforeware and afterware (so, real middleware).

For example:

    app.use(async (ctx, next) => {
        console.log('Request is going down', ctx.request.body)
        await next()
        console.log('Response is coming up', ctx.response.body)
    })
Thanks for the reply.

Curious to know if express v5 would qualify as a "modern" framework (like fastify)?

And hapi! I remember switching to that one from express. Learning it was written by WalMart kinda confused me at first.