An overview of the

Express and Koa are both from the same team, and a comparison of their source code shows that Koa is more mature, the code is easier to read, and the logic is clearer.

For example, Express’s ubiquitous var and Koa’s let and const; Express uses function as its constructor, whereas Koa uses class and extend instead.

Of course, there are also differences in frame thinking, please continue to read.

1. Middleware input parameters

Both Express and Koa enhance NodeJS ‘native HTTP. IncomingMessage and http.ServerResponse, but Koa also integrates both into context context objects.

2. Processing mode of middleware

Many people say that Koa is an onion model and Express is a straight line model.

When middleware is a synchronous function, the result is the same; However, this is not the case when the middleware is an asynchronous function, because Koa’s middleware can return Promise instances, so the order of execution can be controlled via promise.then () or async/await, which Express does not support. It simply passes execution to the next middleware sequentially or ahead of time via next, and if one of the middleware is asynchronous, if you’ve seen JavaScript event loops, we know that the result is not satisfactory.

3. Built-in modules

In contrast to Express, Koa does not have built-in routing capabilities, a template engine, and only middleware modules remain.

However, we can achieve the same function by introducing libraries such as Kow – Router and Kow – View.

The author just gives the choice to the user, but does not delete the function.