Hono vs. H3 vs. HatTip vs. Elysia – modern Express replacements for server (or serverless)

H3 notes that Express.js – old and underdeveloped framework, which is not the optimal choice for new projects due to potential security problems and memory leaks, which, by the way, also applies to Koa.

In our article we will focus on frameworks that support running service workers on the server side and modern standard Fetch APIbecause it allows them to work in serverless and edge environments, such as Cloudflare Workers. This, by the way, is the reason why Fastify will not be considered in our article, despite the experiment fastify-edgewhich lasted two years (by the way, an interesting article on moving from Node to workflow environmentswhich I recommend reading).

Worker Runtimes embody the same language and ability to share code between client and server, which was the original promise of NodeJS, but this did not materialize in practice and the Node and browser APIs went down different paths. Worker Runtimes brings these capabilities back together and more information can be found Here.

Hono, H3, HatTip and Elysia are modern HTTP server frameworks, also known as next-generation web server middleware. They run anywhere, on any JS runtime, including serverless and Edge runtimes, which means they can be used on more than just Node.js servers, and they all support TypeScript.

They all support Web Fetch API (Request/Response objects), but here we will look at their APIs, which are most similar to Expressto make it easier to navigate.

Now let's talk about each of them separately and compare some of the differences.

Hono

API Hono look like Express:

import { Hono } from 'hono';

const app = new Hono();

app.get('/hello', (c) => {

  return c.json({ message: 'Hello!' });

});

export default app;

H3

  • date of creation repository: November 15, 2020;

  • Main participants: 1.5;

  • Stars on GitHub now: 2.9 thousand;

  • Weekly downloads from NPM now: 976 744;

  • Current version: H3 – 1.11.1;

  • Slogan: “A web framework for the modern JavaScript era: an H(TTP) server-side framework built for high performance and portability, running in any JavaScript runtime;”

  • “H3 is composable [и tree-shakeable] framework. Instead of providing a large core, we start with a lightweight instance of the application and there is a built-in utility for each function, or we can create our own. Composable utilities have enormous advantages over traditional plugin/middleware approaches”;

  • H3 was extracted from Nitro/Nuxt around July 2, 2023 (possibly later, which would explain the relatively low number of stars on GitHub);

  • Built primarily for Node, but has adapters for serverless or Edge JS runtimes (e.g. Cloudflare Workers, etc.). H3 can also work on Bun with adapter. This is not yet reflected in bun-http-framework-benchmarkso you can keep an eye on this questionto get the latest updates;

  • H3 integrates with the ecosystem of JS tools from UnJS.

  • NuxtJS (Vue meta framework) built on Nitro (extensions for http server), which is built on H3. Nitro adds file-based routing, resource handling, storage abstraction, etc. on H3. (Nitro may selectively use Vite in one of its routing handlers, since Vite is only needed for the client server, not the static server. according to Nikhil, author Vinxi.)

WITH H3 You can manually register router instances:

import { createApp, createRouter, defineEventHandler, toNodeListener } from "h3";

import { createServer } from "node:http";

export const app = createApp();

const router = createRouter();

app.use(router);

router.get('/', defineEventHandler((event) => {

    return { message: 'Hello!' };

  }),

);

createServer(toNodeListener(app)).listen(8000);

HatTip

HatTip also offers an Express style routing API based on an imperative approach:

import { createRouter } from "@hattip/router";

import { json } from "@hattip/response";

const router = createRouter();

router.get("/", () => {

  return json({ message: "Hello!" });

}

export default router.buildHandler();

ElysiaJS

Elysia uses chained/ smooth interface for type inference, which gives it a unique style:

import { Elysia } from 'elysia'

new Elysia()

    .get('/json', () => ({

        message: 'Hello!'

    }))

    .listen(8080);

Comparison

All of these frameworks follow web standards very actively: Fetch API (existing standard) and WinterCG (future standard).

Stars on GitHub

Hono and Elysia have received a huge number of stars on GitHub.

H3 was pulled from Nitro/Nuxt projects after July 2, 2023. It's possible that users had a preference for higher-level frameworks than H3, which would explain why H3 has fewer stars on GitHub compared to other frameworks, even though it became available for use much earlier (since November 15, 2020).

For the most up-to-date information see: star history chart on GitHub for Hono, H3, HatTip and Elysia.

NPM Installations

H3 is considered one of the most downloaded according to data Moiva.iomost likely because it is included in Nitro and NuxtJS (analogous to NextJS in the Vue world):

If we ignore H3 and look at the situation in more detail, we can see that Hono is in first place, followed by the younger Elysia, and then HatTip (which has not yet reached version 1):

How does their growth rate change? In other words, how fast are they developing?

Hono currently has the fastest growth in monthly NPM downloads at 26.6%. Elysia has 17.9%, followed by HatTip with 17%. It's surprising that the current leader H3 ranks last with a 15.3% increase in monthly NPM downloads.

For the most up-to-date information, check out comparative statistics of NPM and GitHub on Moiva.io for Hono vs. H3 vs. HatTip vs. Elysia.

Performance and benchmarks

All of these frameworks are likely to be fast enough for most use cases. Let's look at some benchmarks.

Web framework benchmark from the repository the-benchmarker on GitHub. Results are presented in requests per second (RPS) at 64 concurrency (HatTip not yet participating in this benchmark.):

Framework

R.P.S.

Hono (Bun)

131 177

H3 (Node?):

75 422

Hono (Node?):

68 263

Elysia (Node?):

64,793

Example HelloWorld benchmark using fastify-uws (using the tool Oha to generate HTTP load for these frameworks):

Framework

R.P.S.

Elysia (Bun)

145 652

Hono (Bun)

117 491

Hono (Node)

65 704

H3 (Node)

64,489

H3 (Bun)

62 165

results HelloWorld benchmark from Denosaurs were excluded from this analysis. This is due to the fact that there were no results for either H3not for HatTip, but only for Hono in Deno environment. Comparing it with Elysia on Bun or with other benchmarks running on different hardware makes little sense. However, we now know about the existence of this benchmark and can improve it by adding these frameworks and/or running it ourselves.

Next let's move on to SaltyAom/bun-http-framework-benchmark (from the author ElysiaJS).

“Running the same code as here again will show completely different performance characteristics compared to a more realistic load profile,” the HatTip author mentions. This confirmed other users. Perhaps the benchmark is biased when does it launch on Windows?

Results, measured in requests per second (RPS), on the official repository benchmark (running on an Intel-Core-i7-13700K processor):

Framework

R.P.S.

Elysia (Bun):

255 574

Hono (Bun):

203 937

H3 (Node):

96 515

Hono (Node):

29,036

Another man ran the same test on Linux on slow computer, but it is worth noting that he did not test other frameworks:

Framework

R.P.S.

Elysia (Bun):

86 841

Hono (Bun):

73 614

One more personusing Linux on slower processor compared to the official benchmark, ran the test:

Framework

R.P.S.

Elysia (Bun):

199 328

Hono (Bun):

196 504

H3 (Node):

95 482

Hono (Node):

20,781

According to reports, Hono is likely can be about 20% faster in the Bun benchmarkhowever on Node Hono seems terribly slow, but this problem is not reflected in the other benchmark – Web framework benchmark.

From the tests performed and the information available, it appears that Elysia and Hono are about equally fast when running on Bun.

Presumably HatTip approximately as fast as Honowhen launched on Bun.

Hono uses faster RegExpRouter instead of a router based Radix Tree (such as Radix3, used in H3). But you should keep an eye on this questionto see if H3 implements the same RegExpRouter or it will be included in radix3. In general, it's probably Router performance won't matter muchsince the execution time of custom logic significantly exceeds it.

Interestingly, some web frameworks that perform worse when processing plain text (such as helloworld) may perform better than others when querying a Postgres database, likely due to specific optimizations, so rankings may vary depending on the specific use case.

Another Node.js benchmark claims: “If you're looking for the most productive Node.js framework, consider that performance of all frameworks degrades when querying the database. In this case, the performance difference between the fastest and the slowest is reduced, and other factors are important“.

Differences/emphases

HatTip pays more attention to standards than Honoespecially when it comes to universal middleware.

Additionally, HatTip focuses on:

While “Hono is just a web framework. This will not change in the future. At least at the current stage there is no option to enable the CLI.”according to its author.

HatTip fits better, i.e. is more deeply integrated with Vite than Hono, which requires plugins.

Other

Advanced tools such as Vinxi (used in Solid Start And Tanstack Start), prefer H3 instead of Hono:

According to Vinxi, it is much better to bet on H3, which is supported by the Nitro and UnJS teams and used by Analog and Nuxt. Lots of people are working to make it stable, fast, bug-free, and work everywhere (and it's still quite a challenge)said Nikhil Saraf (by Vinxi).

But this could also be due to other reasons, such as the ability to manually register router instances in H3 (which is the main feature Vinxi).

That's all, thanks for reading! Share your opinion in the comments(:

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *