Hono vs. H3 vs. HatTip vs. Elysia – modern replacements of Express for a server (or without a server)

Hono vs. H3 vs. HatTip vs. Elysia – modern replacements of Express for a server (or without a server)

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

In our article, we will focus on the frameworks that support it starting service workers on the server side and modern standard Fetch APIas it allows them to work in serverless and Edge environmentssuch 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 to familiarize yourself with).

Worker Runtimes embody the use of a single language and the ability to share code between client and server, which was the original promise of NodeJS, but in practice this has not been realized, and the Node and browser APIs have gone their separate ways. Worker Runtimes combine these capabilities again, and more information can be found here here.

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

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

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

Hono

  • date of creation repository: December 12, 2021;

  • Main participants: 2.5;

  • Stars on GitHub now: 12.4 thousand;

  • Weekly downloads from NPM now: 143,796;

  • Current version: Hono – 4+;

  • Slogan: “Fast, lightweight, meets web standards. Works on any JavaScript runtime”;

  • Created first for Cloudflare Workersbut also has adapter for Nodehowever, using Hono on Node can cause a slowdownbut it doesn’t show up in other tests, e.g. benchmark of web frameworks;

  • Hono is heavily focused on compliance with web standards;

  • Hono supports RPC;

  • Hono aspires to be complex solution: With built-in, custom and third-party middleware and support tools.

API Hono similar to 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;

  • Tagline: “The web framework for the modern JavaScript era: an H(TTP) server framework built for high performance and portability that runs on any JavaScript runtime;”

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

  • H3 was pulled out 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 it questionsto find out about the latest updates;

  • H3 integrates with an ecosystem of tools on JS from UnJS.

  • NuxtJS (Vue meta-framework) built on Nitro (extension for http server), which is built on H3. Nitro adds file-based routing, resource handling, storage abstraction, etc. on H3. (Nitro can optionally use Vite in one of its routing handlers, since Vite is only needed for the client server, not the static server, according to Nikhil, the 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

  • date of creation repository: February 20, 2022;

  • Main participants: 1.5;

  • Stars on GitHub now: 1.1 thousand;

  • Weekly downloads from NPM now: 1,299;

  • Current Version: HatTip – 0.0.44;

  • Slogan: “Like Express, but for the future”;

  • HatTip should work well with Vite-based NextJS alternatives such as Vike (also known as vite-plugin-ssr) or RakkasJSas the HatTip is created @cyco130which is also behind Rakkas. @cyco130by the way, closely cooperates with @brilloutwho is behind Vike and contributes to HatTip;

  • HatTip integrates with graphql-yoga.

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

  • date of creation repository: July 3, 2022;

  • Main participants: 1;

  • Stars on GitHub now: 7.1 thousand;

  • Weekly downloads from NPM now: 23,837;

  • Current Version: Elysia – 1.0;

  • Slogan: “Ergonomic framework for people”

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 these frameworks follow web standards very actively: Fetch API (existing standard) and WinterCG (Standard of the future).

Stars on GitHub

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

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

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

NPM settings

H3 is considered one of the most downloaded by data Moiva.iomost likely because it’s part of Nitro and NuxtJS (the equivalent of NextJS in the Vue world):

Disregarding H3 and taking a closer look, Hono is in first place, followed by the younger Elysia, and then HatTip (which hasn’t reached version 1 yet):

And how does their growth rate change? In other words, how fast are they evolving?

Hono currently has the fastest growth in monthly NPM downloads at 26.6%. Elysia has 17.9%, followed by HatTip with 17%. It is 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 by 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 usage scenarios. Let’s consider some benchmarks.

Benchmark of web frameworks from the repository the-benchmarker on GitHub. The results are presented in requests per second (RPS) at 64 concurrency (HatTip not yet participating in this benchmark.):

Framework

RPS

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 Oh to generate the HTTP payload for these frameworks):

Framework

RPS

Elysia (Bun)

145,652

Hono (Bun)

117 491

Hono (Node)

65,704

H3 (Node)

64,489

H3 (Bun)

62 165

The results the HelloWorld benchmark from Dinosaurs were excluded from this analysis. This is because it had no results for H3not for HatTip, just for Hono in the Deno environment. Comparing it with Elysia on Bun or with other benchmarks run on other hardware made little sense. However, we now know this benchmark exists and can improve it by adding these frameworks and running it ourselves.

Next, let’s go to SaltyAom/bun-http-framework-benchmark (From the author of ElysiaJS).

“Re-executing the same code as here will show completely different performance characteristics compared to a more realistic load profile,” the HatTip author mentions. It is confirmed by other users. Maybe the benchmark is biased, when does windows start?

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

Framework

RPS

Elysia (Bun):

255,574

Hono (Bun):

203,937

H3 (Node):

96,515

Hono (Node):

29,036

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

Framework

RPS

Elysia (Bun):

86,841

Hono (Bun):

73,614

Another personthat uses Linux on slower processor compared to the official benchmark, ran the test:

Framework

RPS

Elysia (Bun):

199,328

Hono (Bun):

196,504

H3 (Node):

95,482

Hono (Node):

20,781

Hono is reportedly likely to can be about 20% faster in the Bun benchmarkhowever, on Node Hono seems to be horribly slow, but this issue is not reflected in another benchmark – Benchmarking of web frameworks.

From the conducted tests and the available information it follows that Elysia and Hono are about equally fast when running on Bun.

Likely, HatTip about as fast as Honowhen running on Bun.

Hono uses faster RegExpRouter instead of router based Radix Tree (such as Radix3, used in H3). But it should be monitored questionsto see if H3 implements the same RegExpRouter or it will be included in radix3. In general, probably the performance of the router will not matter muchsince the execution time of the custom logic is much higher than it.

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

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

Differences / accents

HatTip allocates more attention to standards than Honoespecially when it comes to universal intermediate programs.

In addition, HatTip focuses on:

While “Hono is just a web framework. That won’t change in the future. There’s no way to include a CLI, at least at this stage.”according to its author.

The HatTip is a better fit, i.e. more deeply integrated with the Vite than the Hono needs plugins.

other

Advanced tools such as Vinxi (used in Solid Start and Tanstack Start), prefer H3 over Hono:

In Vinxi’s opinion, it is 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 on making it stable, fast, bug free and working everywhere (and it’s still quite a challenge)said Nikhil Saraf (by Vinxi).

But it can also be caused by other reasons, such as the ability to manually register instances of H3 routers (which is a major feature Vinxi).

That’s it, thanks for reading! Share your opinion in the comments (:

Related posts