Koa
By TJ Holowaychuk and the Koa team
js web framework built by the original creators of Express that uses async functions and middleware to eliminate callback nesting and simplify error handling. It provides no bundled routing, templating, or body parsing, leaving those…
Definition
Koa is a minimal Node.js web framework built by the original creators of Express that uses async functions and middleware to eliminate callback nesting and simplify error handling. It provides no bundled routing, templating, or body parsing, leaving those choices to add-on modules, and instead exposes a small core of context, request, and response objects that middleware compose around, resulting in a smaller, more general foundation than a batteries-included framework.
Overview
Koa exists to address a problem its creators saw in Express: as Node's callback style gave way to promises and async/await, a framework built entirely on synchronous middleware chains and error-first callbacks became awkward for expressing sequential asynchronous logic. Koa was written from the ground up around ES2017 async functions, letting middleware use ordinary try/catch blocks to handle errors from downstream code instead of threading an error object through every callback. Mechanically, Koa organizes its middleware as a stack that executes downstream and then unwinds back upstream, often described as an "onion" model. Each middleware function receives a shared context object and a next function; calling and awaiting next passes control inward, and code after that call runs on the way back out. This lets a single middleware measure response time, add headers after the route handler finishes, or catch exceptions thrown anywhere further down the stack, all without callbacks. Within the Node ecosystem, Koa sits between Express, which bundles more conveniences and callback-based middleware by default, and lower-level HTTP tooling that offers no abstraction at all. Compared to newer entrants like Fastify or Hono, Koa is lighter on built-in performance tooling and schema validation but keeps a smaller, more general core. It shares lineage with Express's philosophy of minimalism but rebuilds the middleware contract around promises rather than trying to retrofit async support onto an older synchronous design. In practice, teams reach for Koa when they want fine control over the request lifecycle without a large bundled framework: APIs, proxies, and internal services where developers hand-pick modules for routing (such as koa-router), body parsing, and session handling. Its context object, which merges request and response helpers into one place, is often cited as more ergonomic than juggling separate req and res parameters, and its generator-then-async evolution made it a proving ground for async middleware patterns later adopted elsewhere. The trade-off is that Koa provides less out of the box than Express or Rails-style frameworks, so a new project spends more time selecting and wiring third-party middleware, and the ecosystem of Koa-specific packages is smaller than Express's. Teams that want batteries-included routing, validation, and OpenAPI generation, or maximum raw throughput, often look instead to Fastify, NestJS, or nginx-fronted alternatives, reserving Koa for cases where the added minimalism and async-first design outweigh the extra assembly work. New contributors also need to learn the onion-style execution order before they can reason confidently about where a given middleware's before-and-after logic actually runs, which is a subtler mental model than Express's more linear callback chain.
Key Features
- Async function middleware avoids callback nesting and error-first callback patterns
- Context object merges request and response helpers into a single interface
- Onion-style middleware execution runs code both before and after downstream handlers
- No bundled router, template engine, or body parser included in the core
- Built by the original Express team as a lighter, more modern successor
- try/catch based error handling propagates naturally through the middleware stack
- Small core codebase keeps the framework's surface area easy to audit
- Large ecosystem of independent middleware packages fills in routing and parsing