3 ms·
Hapi might be an alternative to Express (both are outdated callback-style frameworks), but it's in no way an alternative to Koa.
by onestone 11y ago
Hapi might be an alternative to Express (both are outdated callback-style frameworks), but it's in no way an alternative to Koa.
- l1ambda 11y agoKoa middleware are generally more composable and more robust than Express. In Koa, middleware flows down and up in a stack-like manner with the help of generators. E.g., in Koa you set an X-Response-Time header like so: https://github.com/koajs/response-time/blob/master/index.js https://github.com/koajs/response-time/blob/master/index.js The response time middleware records the start time, then yields to any other middleware, and finally sets the header. You just can't do that as nicely in Express. Here is the Express version: https://github.com/expressjs/response-time/blob/master/index.js https://github.com/expressjs/response-time/blob/master/index... responseTime has to wait to be called via "on-headers". on-headers is a separate module that monkey-patches response.writeHead. The Koa version is 21 lines of code (really just 4 LOC), while the express version is over 200 LOC.