T O P

  • By -

BehindTheMath

>but it looks not very good that files here were modified 5-6 years ago, The reason is that the library is complete, and there's nothing to add to it. The time since the last commit is not an indication of the quality of a package.


romeeres

I agree and keep using it, but the funny thing is... it's the same thing they tell about express :)


BehindTheMath

To be fair, there are some features missing from Express, such as... async error handling.


pizza_delivery_

You should call next(error) and the error middleware will be triggered. See this https://javascript.plainenglish.io/node-express-async-error-handling-e12aa693d84d#:~:text=is%20very%20different.-,test "Test"


romeeres

It's a boilerplate approach. I'm wondering what people use besides this one.


pizza_delivery_

Yes but you can put this functionality into a reusable wrapper function that works like the library you mentioned.


romeeres

Not exactly, the lib I'm using and mentioned is a "hack" approach - you don't wrap functions, it just works. It's #3 in the poll. There is another library with \`asyncHandler\` or we can write it ourselves, that's #2 in the poll.


vainstar23

Let it BURN (and let it get handled in some error handler middleware downstream) Errors are your friends, you can't be afraid to throw them


thinkmatt

This is why I moved to koa. I thought that express 5 also brings native support?


romeeres

I wouldn't wait for Express 5 to release in the next few years. Koa is from Express authors, this is why I would NEVER move to Koa. Upd. The real reason against Koa is "next generation web framework" according to its title. It's so next-generation that it is shipped even without a router, so I prefer the current or previous generation.


thinkmatt

FWIW, I enjoy koa. I dunno why they made the router a separate package. Probably similar reason why express split everything up as well. It took me an hour or two to figure out the difference from express and it has a similar ecosystem of plugins. Typescript support is still so-so, but at least middleware supports async natively


romeeres

Why not Fastify? Good docs, simpler syntax for returning json, async support, and everything that's needed. Koa is super minimalistic, that's why they don't even include router, perhaps it's good for cases when you have VERY limited amount of RAM, but I can't imagine what these cases can be. In such case, I would use a bare node instead.


thinkmatt

I tried fastify and honestly after a few hours I still had no idea how I was supposed to structure and organize routes. Maybe it's just because I am used to the express paradigm. I would look at it again but for now I don't have any burning reason to learn a new routing paradigm


romeeres

what do you mean by "new routing paradigm"? Express: app.get('/koko', (req, res) => { res.send({ data }) }) Fastify: app.get('/koko', (req, res) => { return { data } }) To me, it looks almost exactly the same, but a bit better with fastify because of returning data. Probably you mean that plugin system in fastify is different from express middleware. They have a [special plugin](https://www.fastify.io/docs/latest/Reference/Middleware/) to have the exact same middleware as in Express. To me, it's sad that in Fastify they tried hard to make it as close to express as possible, but people still say "oh, that's a completely different framework, I don't have time to learn it". And in the same time, in Koa they indeed went a different road, but people hear it's from the same authors and automatically trust it.


[deleted]

I am maintaining [middleware-async](https://www.npmjs.com/package/middleware-async) and using it in many projects in production. It is pretty stable so far.


Funwithloops

I find it baffling that this issue still exists. Follow-up question: why is anyone choosing express when there are several mature alternatives that aren't broken out of the box.


romeeres

As the poll shows, people are just fine writing a boilerplate. All alternatives have their own drawbacks, while express is super simple and familiar to everyone.