Should I be using KOA or Express?

I've heard that KOA is more "lightweight" than Express JS...but Express still seems to be the most popular?

Any strong opinions on why you would use one over the other?


Answers

S
Samara.Klocko

Cleaner syntax...

  1. const asyncWrapper = fn => (...args) => fn(...args).catch(args[2]);
  2. app.get("/", asyncWrapper(async (req, res, next) => {
  3. const result = await asyncActivity();
  4. res.json(result);
  5. })

vs.

  1. router
  2. .get("/", async (context, next) => {
  3. const result = await asyncActivity();
  4. context.body = result
  5. });

basically...

M
Mario75

Use KOA if your app isn't browser based. For example, if you are building a backend service that doesn't require templating and other browser specific middleware then you should use KOA. It's more lightweight and supposed to be significantly faster under the right performance tests.

This is not to say that you can't do certain things in one and not the other. While KOA is more lightweight there are tons of additional modules that make it do everything Express can. For example the koa-router module allows you to write routing using KOA.

J
Jerad_Kling4

Apparently KOA could be considered "Express 5"...same development team and everything...just saying

T
Triston63

KOA is more light weight. It doesn't have all the bells and whistles included with Express (templating, sending files, etc).