express vs hapi vs hono vs koa
Selecting the Right Node.js Web Framework for Backend Services
expresshapihonokoaSimilar Packages:

Selecting the Right Node.js Web Framework for Backend Services

express, hapi, hono, and koa are all popular Node.js frameworks used to build web servers and APIs, but they differ significantly in architecture, middleware handling, and target environments. express is the long-standing standard known for its minimalism and massive ecosystem. hapi emphasizes configuration over code and strong built-in security features. koa is created by the Express team to be more modern and expressive using async functions. hono is a newer, ultrafast framework designed for edge computing environments like Cloudflare Workers, while still running on Node.js.

Npm Package Weekly Downloads Trend

3 Years

Github Stars Ranking

Stat Detail

Package
Downloads
Stars
Size
Issues
Publish
License
express068,95875.4 kB1893 months agoMIT
hapi014,776-587 years agoBSD-3-Clause
hono029,3001.36 MB344a day agoMIT
koa035,74365 kB2714 days agoMIT

Express vs Hapi vs Hono vs Koa: Architecture, Middleware, and Runtime Compared

When building backend services in the Node.js ecosystem, choosing the right framework shapes your entire development experience. express, hapi, hono, and koa all handle HTTP requests, but they solve routing, middleware, and error handling in fundamentally different ways. Let's break down how they tackle common engineering challenges.

🛣️ Routing and Handler Definitions

express uses a simple, imperative approach where you attach methods directly to the app instance.

  • Routes are defined by HTTP verb and path.
  • Handlers receive req and res objects explicitly.
// express: Imperative routing
const express = require('express');
const app = express();

app.get('/users/:id', (req, res) => {
  res.json({ id: req.params.id });
});

hapi relies on a configuration object to define routes.

  • You define routes in an array and pass them to the server.
  • This separates route logic from server setup, which helps in large teams.
// hapi: Configuration-based routing
const server = Hapi.server({ port: 3000 });

server.route({
  method: 'GET',
  path: '/users/{id}',
  handler: (request, h) => {
    return { id: request.params.id };
  }
});

hono uses a chainable API that feels similar to Express but is optimized for speed and edge runtimes.

  • It supports typed routing when used with TypeScript.
  • Handlers return responses directly or use context helpers.
// hono: Chainable routing
import { Hono } from 'hono';
const app = new Hono();

app.get('/users/:id', (c) => {
  return c.json({ id: c.req.param('id') });
});

koa also uses a chainable approach but focuses on the context object ctx.

  • Routes are attached via middleware functions.
  • It does not bundle a router by default; you typically add @koa/router.
// koa: Context-based routing (with @koa/router)
const Koa = require('koa');
const Router = require('@koa/router');
const app = new Koa();
const router = new Router();

router.get('/users/:id', (ctx) => {
  ctx.body = { id: ctx.params.id };
});

app.use(router.routes());

🧩 Middleware and Flow Control

express uses a callback-based middleware system.

  • You must call next() to pass control to the next function.
  • Mixing async code with next() can lead to tricky bugs if not handled carefully.
// express: Callback middleware
app.use((req, res, next) => {
  console.log('Time:', Date.now());
  next(); // Must call next to continue
});

hapi uses an extension point system (lifecycle methods).

  • You register functions at specific points like onRequest or preHandler.
  • This is more rigid but prevents accidental order dependencies.
// hapi: Lifecycle extensions
server.ext('onRequest', (request, h) => {
  console.log('Time:', Date.now());
  return h.continue; // Must return continue
});

hono uses a modern middleware stack similar to Koa but lighter.

  • It supports async/await natively without needing next() in many cases.
  • Middleware can modify the context before passing it on.
// hono: Async middleware
app.use('*', async (c, next) => {
  console.log('Time:', Date.now());
  await next(); // Wait for downstream middleware
});

koa introduced the "async function" middleware pattern.

  • You use await next() to yield control, which makes flow look synchronous.
  • This eliminates the "callback hell" common in older Express apps.
// koa: Async/await middleware
app.use(async (ctx, next) => {
  console.log('Time:', Date.now());
  await next(); // Yield control cleanly
});

🚨 Error Handling Strategies

express relies on a specific error-handling middleware signature.

  • You must define a function with four arguments (err, req, res, next).
  • If you miss an argument, Express will not treat it as an error handler.
// express: Special error handler
app.use((err, req, res, next) => {
  console.error(err.stack);
  res.status(500).send('Something broke!');
});

hapi handles errors via response objects or throwing errors in handlers.

  • It has built-in support for returning standardized error responses.
  • You can configure global error handlers in the server options.
// hapi: Throw or return error
server.route({
  method: 'GET',
  path: '/error',
  handler: (request, h) => {
    throw new Error('Something broke!'); // Caught by hapi
  }
});

hono uses a centralized error handler that catches thrown exceptions.

  • You register an onError handler to format the response.
  • It works seamlessly with async/await try/catch blocks.
// hono: Centralized error handler
app.onError((err, c) => {
  console.error(err);
  return c.text('Internal Error', 500);
});

koa handles errors via standard try/catch blocks in async functions.

  • Since middleware is async, you can catch errors naturally.
  • It also emits an error event on the app instance for unhandled cases.
// koa: Try/catch or app event
app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    ctx.status = 500;
    ctx.body = 'Something broke!';
  }
});

☁️ Runtime and Deployment Targets

express is designed primarily for standard Node.js environments.

  • It depends on Node's built-in http module.
  • Running it on edge runtimes usually requires a compatibility layer or adapter.
// express: Node.js http server
const http = require('http');
const server = http.createServer(app);
server.listen(3000);

hapi also targets standard Node.js servers.

  • It is heavy on dependencies and setup, making it less ideal for serverless cold starts.
  • Best deployed on long-running containers or traditional VMs.
// hapi: Node.js server start
await server.start();
console.log('Server running on %s', server.info.uri);

hono is runtime agnostic and built for the edge.

  • It runs on Cloudflare Workers, Deno, Bun, and Node.js without changes.
  • This makes it highly portable across different hosting providers.
// hono: Export for any runtime
export default app;
// Deployed directly to Cloudflare Workers or Bun

koa runs on Node.js but is lighter than Express.

  • It does not include a request handler, giving you more control.
  • Like Express, it is not natively designed for edge runtimes without adapters.
// koa: Node.js listener
app.listen(3000, () => {
  console.log('Server running');
});

🤝 Similarities: Shared Ground Between Frameworks

While the differences are clear, all four frameworks share core concepts as HTTP servers.

1. 🌐 HTTP Request/Response Cycle

  • All handle incoming HTTP requests and send responses.
  • Support standard methods like GET, POST, PUT, DELETE.
// All frameworks support basic JSON responses
// express: res.json({ ok: true })
// hapi: return { ok: true }
// hono: return c.json({ ok: true })
// koa: ctx.body = { ok: true }

2. 🔌 Middleware Architecture

  • All allow you to intercept requests before they reach the handler.
  • Used for logging, authentication, and parsing bodies.
// All support logging middleware
// express: app.use(logger)
// hapi: server.ext('onRequest', logger)
// hono: app.use('*', logger)
// koa: app.use(logger)

3. 🔒 Security Extensions

  • All rely on community or built-in packages for security headers.
  • Helmet (Express), hapi plugins, Hono built-ins, Koa middleware.
// Example: Setting security headers
// express: app.use(helmet())
// hapi: server.register(require('hapi-helmet'))
// hono: app.use(secureHeaders())
// koa: app.use(koaHelmet())

4. 📦 Ecosystem Support

  • All have npm packages for database integration, auth, and validation.
  • Express has the largest, Hono is growing fast in edge spaces.
// Example: Database connection
// All can use standard drivers like pg or mongoose
// const db = await mongoose.connect(...)

📊 Summary: Key Similarities

FeatureShared by All Four
Core Function🌐 HTTP Server Handling
Extensibility🔌 Middleware/Plugin System
Language🟨 JavaScript/TypeScript
Package Manager📦 npm/yarn/pnpm
Security🔒 Middleware/Plugin based

🆚 Summary: Key Differences

Featureexpresshapihonokoa
Middleware🔄 Callback (next())🛠️ Lifecycle Extensions⚡ Async/Await⚡ Async/Await (await next)
Routing🗂️ Imperative Methods📝 Config Object⛓️ Chainable API🗂️ External Router Needed
Runtime🖥️ Node.js Only🖥️ Node.js Only🌍 Edge + Node + Deno🖥️ Node.js Only
Error Handling⚠️ 4-Arg Function🛑 Throw/Return🛑 Try/Catch + Handler🛑 Try/Catch
Philosophy🧰 Minimal, Unopinionated🏢 Enterprise, Config-heavy🚀 Fast, Edge-First🎨 Modern, Express Evolution

💡 The Big Picture

express is the reliable workhorse 🐎—it has been the standard for a decade and has a plugin for everything. Choose it for traditional Node.js APIs where stability and community support matter most.

hapi is the enterprise fortress 🏰—it enforces structure and security through configuration. Choose it for large teams building complex services where consistency and safety are paramount.

hono is the speedster 🏎️—built for the modern web edge. Choose it if you are deploying to Cloudflare Workers, Deno, or need the smallest possible footprint with high performance.

koa is the modern evolution 🧬—it fixes Express's async pain points without changing the mental model too much. Choose it if you want a cleaner codebase than Express but still want to stay within the Node.js ecosystem.

Final Thought: There is no single "best" framework. express wins on ecosystem, hono wins on performance and portability, hapi wins on structure, and koa wins on developer experience for async code. Match the tool to your deployment target and team needs.

How to Choose: express vs hapi vs hono vs koa

  • express:

    Choose express if you need a stable, battle-tested framework with the largest ecosystem of middleware and plugins. It is ideal for traditional Node.js server deployments where community support and finding solutions to common problems quickly are top priorities. However, be aware that it relies on callback-style middleware which can feel dated compared to modern async/await patterns.

  • hapi:

    Choose hapi if you are building enterprise-grade applications that require strict input validation, authentication, and security policies out of the box. It favors configuration over code, which reduces the risk of developer error in large teams. It is best suited for complex API services where maintainability and security are more critical than raw performance or minimal setup.

  • hono:

    Choose hono if you are targeting edge runtimes like Cloudflare Workers, Deno, or Bun, or if you need extremely low latency and small bundle sizes. It is designed to be lightweight and fast, making it perfect for serverless functions and modern Jamstack backends. If you need a framework that works seamlessly across different JavaScript runtimes without heavy dependencies, this is the strongest candidate.

  • koa:

    Choose koa if you want a modern, expressive foundation built by the Express team but without the baggage of legacy callback patterns. It uses async functions for middleware, making error handling and flow control much cleaner. It is a great middle ground for developers who want the flexibility of Express but prefer modern JavaScript syntax and better error handling capabilities.

README for express

Express Logo

Fast, unopinionated, minimalist web framework for Node.js.

This project has a Code of Conduct.

Table of contents

NPM Version NPM Downloads Linux Build Test Coverage OpenSSF Scorecard Badge

import express from 'express'

const app = express()

app.get('/', (req, res) => {
  res.send('Hello World')
})

app.listen(3000, () => {
  console.log('Server is running on http://localhost:3000')
})

Installation

This is a Node.js module available through the npm registry.

Before installing, download and install Node.js. Node.js 18 or higher is required.

If this is a brand new project, make sure to create a package.json first with the npm init command.

Installation is done using the npm install command:

npm install express

Follow our installing guide for more information.

Features

  • Robust routing
  • Focus on high performance
  • Super-high test coverage
  • HTTP helpers (redirection, caching, etc)
  • View system supporting 14+ template engines
  • Content negotiation
  • Executable for generating applications quickly

Docs & Community

PROTIP Be sure to read the migration guide to v5

Quick Start

The quickest way to get started with express is to utilize the executable express(1) to generate an application as shown below:

Install the executable. The executable's major version will match Express's:

npm install -g express-generator@4

Create the app:

express /tmp/foo && cd /tmp/foo

Install dependencies:

npm install

Start the server:

npm start

View the website at: http://localhost:3000

Philosophy

The Express philosophy is to provide small, robust tooling for HTTP servers, making it a great solution for single page applications, websites, hybrids, or public HTTP APIs.

Express does not force you to use any specific ORM or template engine. With support for over 14 template engines via @ladjs/consolidate, you can quickly craft your perfect framework.

Examples

To view the examples, clone the Express repository:

git clone https://github.com/expressjs/express.git --depth 1 && cd express

Then install the dependencies:

npm install

Then run whichever example you want:

node examples/content-negotiation

Contributing

The Express.js project welcomes all constructive contributions. Contributions take many forms, from code for bug fixes and enhancements, to additions and fixes to documentation, additional tests, triaging incoming pull requests and issues, and more!

See the Contributing Guide for more technical details on contributing.

Security Issues

If you discover a security vulnerability in Express, please see Security Policies and Procedures.

Running Tests

To run the test suite, first install the dependencies:

npm install

Then run npm test:

npm test

Current project team members

For information about the governance of the express.js project, see GOVERNANCE.md.

The original author of Express is TJ Holowaychuk

List of all contributors

TC (Technical Committee)

TC emeriti members

TC emeriti members

Triagers

Triagers emeriti members

Emeritus Triagers

License

MIT