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.
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.
express uses a simple, imperative approach where you attach methods directly to the app instance.
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.
// 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.
// 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.
@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());
express uses a callback-based middleware system.
next() to pass control to the next function.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).
onRequest or preHandler.// 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.
next() in many cases.// 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.
await next() to yield control, which makes flow look synchronous.// koa: Async/await middleware
app.use(async (ctx, next) => {
console.log('Time:', Date.now());
await next(); // Yield control cleanly
});
express relies on a specific error-handling middleware signature.
(err, req, res, next).// 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.
// 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.
onError handler to format the response.// 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.
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!';
}
});
express is designed primarily for standard Node.js environments.
http module.// express: Node.js http server
const http = require('http');
const server = http.createServer(app);
server.listen(3000);
hapi also targets standard Node.js servers.
// 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.
// 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.
// koa: Node.js listener
app.listen(3000, () => {
console.log('Server running');
});
While the differences are clear, all four frameworks share core concepts as HTTP servers.
// 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 }
// All support logging middleware
// express: app.use(logger)
// hapi: server.ext('onRequest', logger)
// hono: app.use('*', logger)
// koa: app.use(logger)
// Example: Setting security headers
// express: app.use(helmet())
// hapi: server.register(require('hapi-helmet'))
// hono: app.use(secureHeaders())
// koa: app.use(koaHelmet())
// Example: Database connection
// All can use standard drivers like pg or mongoose
// const db = await mongoose.connect(...)
| Feature | Shared by All Four |
|---|---|
| Core Function | 🌐 HTTP Server Handling |
| Extensibility | 🔌 Middleware/Plugin System |
| Language | 🟨 JavaScript/TypeScript |
| Package Manager | 📦 npm/yarn/pnpm |
| Security | 🔒 Middleware/Plugin based |
| Feature | express | hapi | hono | koa |
|---|---|---|---|---|
| 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 |
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.
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.
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.
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.
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.
Fast, unopinionated, minimalist web framework for Node.js.
This project has a Code of Conduct.
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')
})
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.
PROTIP Be sure to read the migration guide to v5
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
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.
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
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.
If you discover a security vulnerability in Express, please see Security Policies and Procedures.
To run the test suite, first install the dependencies:
npm install
Then run npm test:
npm test
For information about the governance of the express.js project, see GOVERNANCE.md.
The original author of Express is TJ Holowaychuk