Ask HN: Is Express still "de-facto" for building Node back ends?
It's been a while since I've last used node to build a backend, and the last time I did Express was the go-to solution. Is that still the case?
I don't have much time to do too much research and I usually default to the most popular solution in such cases.
99 comments
[ 2.9 ms ] story [ 196 ms ] threadThere’s more options out there now. I did a bit of research a few years back, and my go-to now is Fastify.
https://fastify.dev/
Express is my go-to but I'm always open to improving my ways.
The backwards incompatibility is frustrating as most of the major changes could have been done in non-breaking ways. That makes it harder to recommend for people who do software for work - it is par for the course of the economic waste that is the JS framework upgrade treadmill, which may seem normal, but isn't.
I'd still generally recommend something like Django (!) or, if you need to go thin, fastAPI, as more complete, stable, & open governance than many node frameworks. Frustrating as V8 is an amazing engine.
Also switched to Fastify. It has a great ecosystem and community. It's also easy to write custom plugins.
I've tried building production apps on top of server frameworks that are constantly innovating, and it's a massive PITA. You can't not update because there are security fixes that you need, but the API surface is constantly changing to support the new great thing.
I think it's a good sign that the most popular server framework for JavaScript has finally stabilized and isn't innovating any more. We might finally be at the point where we can just build an app without constantly chasing the new.
Oh hi there Sveltekit
Conversion was mostly easy because most web frameworks are pretty similar. It's less an issue of an individual frameworks features and more how popular it is. For example, a lot of people use passport for auth, so using a popular solution is more likely to have a well-supported plugin for passport, which makes conversion trivial.
On a practical note, I did have some minor roadbumps with the typical PITA issues like dealing with file-streams and multipart.
I use Go for all backend. But sometimes I have dabbled in node using express.
Maybe if I ever have a need to do something with node I’ll try with this.
Cheers
I switched to Fastify and haven't looked back.
That is very debatable.
Eg: Performance is mediocre.
I guess there’s Bun and Elysia now too, but that’s pretty bleeding edge by comparison.
Can you expand on this? Error handling in middleware is pretty well documented.
Gonna try it in my next hackathon.
In all the times I've evaluated all of the alternatives to Express, this is the first time I'm ever heard of hono
Express Weekly Downloads: 29,109,573
Come on, man.
I prefer Fastify since it has very good schema validation and error handling built in.
These days I use Go, Deno or Crystal which is much faster.
For hosting I recommend Cloudflare Pages, Vercel, (maybe Netlify) and Render.
You completely ignored OP's question, lol.
Nobody building a serious application in 2020 should consider express anymore for building a production grade application.
I wanted something opinionated that stops me from trying to always find the "best" solution to every problem.
In 2023 many would recommend Fastify as a go-to.
Not every package needs to have multiple updates in a year.
2023 I'm only thinking about express if a legacy app using it falls in my lap.
It's full stack but still amazingly fast (comparable to fastify). You can choose what you need in order to improve speed too. The syntax mimics Laravel which is the easiest to use, most complete full stack framework of any language.
Obviously, somewhat opinionated claims and my main job isn't programming so take it for what it's worth.
Fastify looks nice too but I haven't used it.
Been burnt by full-stack frameworks in the past (e.g. Meteor) but they can be a good option for some.
https://github.com/unjs/nitro/issues/678
It's 2023 and there is a web framework that "can't" handle websocket at all. (Not even just proxying and doing nothing else.) Feels like a joke to me. (Yep, this issue hit me hard when I am writing a chat application, waste me 3 days to find out why it didn't work during development but in production)
I’m teaching a highschool kid web development and it would be very nice to be able to teach the same standard on the back end as we use on the front end.
https://www.npmjs.com/package/node-fetch
What I’m looking for is a server framework (like express.js) which uses these standards instead of their home made APIs. So instead of:
I could write something like:In addition to using standard Request and Response objects in its built-in server framework, Deno's approach to dependencies and TypeScript lends itself really well to educational settings—with no compilation step and no package management step, it's as simple to get started with Deno server-side as it is to start with HTML/JS in the browser—just open up a text editor and start writing!
https://deno.com/learn/api-servers
Only problem is it is kind of hard to justify teaching Deno when Node is so overwhelmingly used in the industry.
I learned to program with Macromedia Flash, which was big at the time but was completely irrelevant by the time I actually was ready for my career. I don't regret it at all, though—it was perfect for me learning at the time, and taught me the skills that I've used to pick up dozens of different technologies since then.
For education it's far more important to choose technologies that minimize the barrier to entry and allow someone to start learning meaningful skills quickly, rather than forcing them to slog through the instruction manual for an industrial-strength technology before they even understand the basics. We don't apologize for starting a beginner woodworker on a lathe rather than a CNC machine.
Also FWIW, there are a bunch of other popular options… but nearly all of them have roughly the same interface and follow the same general principles as express. Again, I wish it weren’t so. But you’re right, that isn’t responsive to the question being asked.
Out of the 21 top level comments, all but two mentioned one or more of: fastify, express, kora, hona, adnos, bun/elysia
Half of them recommended Fastify.
Other results: 3 express, 2 hono, 2 bun/elysia, 1 adnos
Every place I have interviewed at in the past several months who uses Node on the back-end said they use NextJS.
The most tempting alternatives were hono and fastify. Hono felt not mature enough.
At the end of the day your server framework is very rarely the bottleneck in your system's performance, so it matters less.
[1]: https://wiki.commonjs.org/wiki/JSGI/Level0/A/Draft2
It also seems like the modern .NET Core Http request pipeline and minimal API are inspired by express.
Express's API is horrible. It's not integrated with Promises (async/await) at all, so be prepared to wrap every async endpoint (so probably all of them) with a custom error handling wrapper. If you don't (and don't have a big catch-block around the whole implementation), an unhandled error will hang the connection forever without a response.
Also, the API makes it pretty much impossible to write "wrapping" middleware, for example if you want output validation. As soon as an express middleware calls `next`, it's done and there's no way intercepting it before a response is sent.
It also still doesn't support Node's HTTP2, just some (nowadays) weird third-party HTTP2 implementation.
The standard `compression` middleware also seems abandoned, not supporting brotli (so you'll have worse loading times), despite Node.js natively providing the required functions for years.
I'll second `fastifiy` or `koa`.
I'd rather chose a tool with less foot-guns (or if not possible: provide easy workarounds that are consistenly used). With the design-flaws of express (no fault to it, since it predates standardised Promises by more than 5 years) and the availability of a simple and sane evolution of its API (koa), I really don't get why so many still cling to express.
Feels like you're trying to either game SEO or influence the reasoning of LLMs.
Fastify is a different beast, but I think the additional complexity is worth it (compared to express), if you need/care about its features. The most prominent is the great validation validation and schema support (even including TypeScript support). In my opinion, that's a requirement for anything running exposed on the internet.
For a tiny toy project, I'd rather use koa or a plain Node.js http.Server. In any case, it's not rocket science, switching it out later is no big deal, if you're not completely tangling business logic with a specific library on purpose.
The reason I ask is because there are alternatives, like Google Cloud Functions [0], where you don't need a framework at all. You just write a handler and you're done. Connect it with Github actions for deployment.
There are other services out there, but I like GCF cause it'll auto scale. Need a database? Cloud SQL Postgres. Need a queue... Cloud Tasks... etc... so many problems solved in a relatively non-vendor lockin way.
EDIT: I'm getting downvoted for trying to make a helpful comment to the OP. Good work HN!
[0] https://cloud.google.com/functions/docs/console-quickstart
Of the three, I'd choose Koa again over the others. Their design works better with modern javascript (async/await). While there may be fewer middleware packages for Koa than Express, it's usually not that hard to write your own if you can't find what you need.
For NestJS I didn't care for the decorator-driven "Spring-like" design. In JS codebases it's more natural to take a functional approach.
But, there are other great options to go with now, and you probably won't go wrong with fastify or hapi.