Hacker News new | past | comments | ask | show | jobs | submit login
Express 5.0 – Last Push (github.com/expressjs)
40 points by rareitem 20 days ago | hide | past | favorite | 17 comments



Wild, this 5.0 release has been cooking since 2014: https://github.com/expressjs/express/blob/5.x/History.md#500...

That’s also the full 5.0 change log so far for anyone interested.


I can't believe it finally happened, 10 years later. Congratulations to the team for finally finishing.

In the meantime I've gotten so sick of js-isms i jumped ship and no longer want to touch it. Server-side nodejs libraries have always felt less mature and more prone to excessive complexity than their counterparts.

Python+sqlalchemy+sanic/other lightweight HTTP server is just so much more comfortable to me nowadays. Much less performant, though, but a painless development experience that lets me focus on the task at hand just feels better.

Maybe I'll port some of my legacy nodejs stuff to express 5 for fun.


Same. Moved to laravel and honestly happy that I left the js ecosystem.


Where does this version of express put it against its competitors (Koa, Fastify, Hono etc)?


Koa hasn't really been a thing since async/await came to JS and addressed most if not all of the pain points in Express that Koa initially was created to alleviate (the pyramid of doom being the main one).

It seems like there is still occasional work there, but it seems more like bare minimum bugfixes and docs improvements. I've maybe seen one company using Koa in the last 5 years.

Fastify would be the closest modern framework, but it's a significant departure from both Express and Koa, taking the convention over configuration approach, but it's not batteries-included.


What are you talking about WRT Koa? Express 4 does not support async/await natively in its middleware. That means if your async method throws an error, you need to catch it and return it yourself or else it will just crash the app. That's one reason why I currently use Koa. Express 5 finally supports async/await and it is only now being officially released.


You can fix async await with express by just installing a package.


Which package?


This one does it via monkey patching express internals to make the fix transparent: https://www.npmjs.com/package/express-async-errors


That still doesn't address the main difference between Express and Koa.

In Express, the route handlers send the response directly so your middleware can only be "beforeware".

In Koa, the route handlers update a response object that bubbles back up the stack before it's sent, so you can write both beforeware and afterware (so, real middleware).

For example:

    app.use(async (ctx, next) => {
        console.log('Request is going down', ctx.request.body)
        await next()
        console.log('Response is coming up', ctx.response.body)
    })


Sure, but that doesn’t seem very relevant to this thread. Also in express there are certainly ways to do what you say, for instance you could make a middleware like the following:

    app.use(async (req, res, next) => {
      console.log("Request is going down", req.body)
      await next()
      console.log("Response is coming up", res.data)
      res.send(res.data)
    })

    app.get("/", function (req, res) {
      res.data = { content: "Hello World" }
    })


I don't think anyone was claiming Express and Koa were carbon copies of one another, only that Koa's benefits over Express are minor and Express is much more relevant.

Your claim that "you have to catch your errors or your app can crash" can be addressed trivially. My Express is rusty and I didn't use exact types, but something like this would do:

    type ExpressMiddlewareNextOptional = (req: Record<any, any>, res: Record<any, any>, next?: (error: any) => void) => any;
    type ExpressMiddleware = (req: Record<any, any>, res: Record<any, any>, next: (error: any) => void) => any;

    const mid = (middleware: ExpressMiddlewareNextOptional): ExpressMiddleware => {
      return (req, res, next) => {
        const result = middleware(req, res, next);
        if (result instanceof Promise) {
          result.catch((err) => next(err));
        }
      }
    }
    
    // example usage:
    app.get('somepath', mid(async (req, res) => {
      throw new Error('Oopsie!')
    }))
I used Koa a long time ago before JS had promises and async/await, and it was a relief then, but since Promises the ergonomics of Express have been better (compared to Koa of 8-9 years ago, it's possible Koa is on par or better now). When I started a new project 4 years ago I saw that express had >100X the active usage of Koa, and many, many more packages and pre-built middleware. That's why I say Koa is largely not relevant.

They're both very lightweight libraries, but the ecosystem for Express is much larger, and as mentioned, I've seen maybe 1 company using Koa in the last 5 years. I'm not saying not to use it, and I'm not saying it's not good, but OP was asking for a comparison to "competitors", and I think the ecosystem around a web framework is one of the most important considerations in choosing one. There are thousands of Node.js frameworks, and I'm sure there are many novel ideas among many excellent frameworks I've never even heard of, but the only ones I'd call "competitors" to Express are the ones operating in or near the same weight class. OP mentioned Fastify which is no more than 1 order magnitude away from express in market share, and Koa, which is at least 2 orders of magnitude below Express in active market share. My response was just pointing out that Koa is largely irrelevant when considering Node.js frameworks as "competition to Express".

If they had asked about "alternatives" instead I probably wouldn't have mentioned it "not being a thing", but just pointed out that Express/Koa are spiritually very similar (as two ultra-minimalist frameworks created by TJ Hollowaychuk), but Express's ecosystem is so much larger that someone who isn't already familiar with Koa would very likely be better off choosing Express for anything serious.


Express definitely has a bigger ecosystem and it's what most people, especially beginners, should use.

But they asked how Express 5 compared to competitors, you brought up Koa, someone suggested that Koa was superseded by async/await + some library in Express, and I pointed out Koa's little native feature that still makes it relevant to the few of us who ever used it.

I don't put a lot of importance on microframework ecosystems because 99% of their library middleware is just trivial wrappers around core libraries like https://github.com/jshttp. I write my own glue code in middleware and Koa's abstraction is just what I expect from server code.


Thanks for the reply.

Curious to know if express v5 would qualify as a "modern" framework (like fastify)?


And hapi! I remember switching to that one from express. Learning it was written by WalMart kinda confused me at first.


Is there a link to the list of main new features?





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: