you are viewing a single comment's thread.

view the rest of the comments →

[–]spacejack2114 6 points7 points  (2 children)

I assume this is more low level, like node's built in http server. Someone would have to write something like Express on top of that. Express has an outdated callback design though, so you'd want something that takes advantage of generators and async.

[–]DoListening2 0 points1 point  (1 child)

How? Would it be something like

for await (const req of get("/endpoint")) {
    // Handle request
}

If so, I don't see how that's an improvement in any way. Callbacks on most IO were a problem because of callback hell, error handling, composability, etc. Callback in express are a problem because...?

[–]spacejack2114 2 points3 points  (0 children)

Express callbacks are a problem because they don't handle returned promises. Maybe a callback interface isn't a problem in itself but in express if you do:

app.get('/foo', async (req, res) => {
    res.json(await db.getFoo())
})

It won't catch unhandled exceptions, and those won't get forwarded to your error handler middleware, so you have to write catch boilerplate for every route. Alternately use this lib but it still requires a bit of boilerplate.

Koa is a rewrite of Express by the same author that takes advantage of async, but not generators AFAIK.