TopGit
GitHub Repo Review

Koa: the koa nodejs framework without bundled middleware

koajs/koa
KTopGit review image for koajs/koa
Review by Topgit.dev for koajs/koa, with GitHub repository stats and README context.
Quick verdict

Koa is a lean async middleware framework for Node.js, built around ES2017 async functions instead of callbacks. It ships with zero bundled middleware — no router, no body parser — so it isn't a batteries-included pick out of the box. What you get instead is a cleaner mental model: each middleware awaits next(), then keeps running after the response comes back, without the nested-callback mess older Node frameworks needed.

Stars
★ 35.7k
Forks
⑂ 3.3k
Language
JavaScript
License
MIT
Topic
—
Updated
Nov 2026
Homepage
GitHub

What is Koa?

Koa is a minimal HTTP middleware framework for Node.js, built by the team behind Express to run on ES2017 async functions instead of callbacks. Every request gets a single ctx object bundling Koa's Request and Response together, and middleware runs in a stack — downstream, then back upstream after next() resolves. Koa ships with no bundled middleware, not even a router, so what you get is the dispatch core, not a full framework out of the box.

Key features that set Koa apart

  • ✓Middleware runs in a stack: each handler executes code before await next(), then more code after it resolves, so logging or timing wraps the whole downstream chain in one function.
  • ✓A single ctx object bundles the request and response together for each call, with shortcuts like ctx.body and ctx.type instead of reaching into ctx.request or ctx.response separately.
  • ✓Koa delegates to Node's raw IncomingMessage and ServerResponse (exposed as ctx.req and ctx.res) instead of monkey-patching them, which the README says avoids conflicts between middleware that would otherwise extend the same objects differently.
  • ✓Content negotiation and normalization of Node's http inconsistencies are built into the core, per the README, rather than left to a separate package.
  • ✓Middleware can be a plain async function or a common function returning a promise — both signatures work side by side.
  • ✓The codebase is small (the README puts it around 570 SLOC), which keeps the surface area you have to learn to almost nothing.
How this repository's GitHub stars have grown over time. Source: star-history.com.View the star history ↗

Installing Koa

Run npm install koa. Koa requires Node v18.0.0 or higher for the ES2015 and async function support it depends on — the README states this as a hard minimum, not a recommendation. There's no CLI or project scaffolding; you require('koa') and instantiate new Koa() yourself.

Writing your first Koa app

The README's own example is about as small as a working server gets: ```js const Koa = require('koa'); const app = new Koa(); app.use(ctx => { ctx.body = 'Hello Koa'; }); app.listen(3000); ``` app.use() registers middleware, ctx.body sets the response, and app.listen() starts the Node http server underneath. Add async (ctx, next) middleware ahead of that handler and you can run code before and after it runs, by awaiting next().

What you can build with Koa

  • •Hand-rolled HTTP APIs where you want to pick your own router, validator, and body parser instead of accepting a framework's defaults.
  • •Streaming responses — the README's own example pipes a file straight into ctx.body via a Node read stream.
  • •Custom error-handling middleware, since try/catch around await next() catches everything downstream in one place.
  • •Small internal services where the ~570 SLOC core is easier to audit than a heavier framework.

Strengths

  • ✓The onion-style middleware model makes cross-cutting concerns (logging, timing) simple with async/await, no callback pyramid.
  • ✓Delegating to Node's raw IncomingMessage/ServerResponse instead of extending them avoids the conflicts you get when several middleware packages all patch the same objects.
  • ✓Tiny core (the README puts the codebase around 570 SLOC) keeps the surface area small enough to read in an afternoon.
  • ✓The ctx object bundles request/response shortcuts (ctx.type, ctx.accepts) so common tasks skip the extra hop through request or response.
  • ✓CI status and test coverage are tracked in the open, right on the README, via GitHub Actions and Codecov.

Koa's limitations

  • △No bundled middleware at all — routing, body parsing, static file serving, and sessions all come from separate koa-* packages you pick yourself.
  • △The v1.x middleware signature (generator-based) was deprecated in v2 and removed outright in v3, so anything written against the old docs needs a migration pass.
  • △Requires Node v18+ per the README, ruling it out for teams stuck on older LTS runtimes.
  • △Minimal core means less hand-holding: no CLI scaffolding, no opinionated project structure — you assemble the stack yourself.

Koa vs Express and other alternatives

express — Koa's predecessor from the same original team; bundles routing and more by default where Koa ships empty, at the cost of callback-style middleware. ↗Hapi — a configuration-driven Node framework with built-in validation and route config, for teams that want more decided for them than Koa provides.Fastify — a Node framework built for request-handling throughput with a plugin system, an alternative for teams whose main constraint is raw performance rather than Koa's minimal core.

Frequently asked questions about Koa

What Node.js version does Koa require?

Koa requires Node.js v18.0.0 or higher, per the project's README, since it depends on ES2015 and async function support built into that runtime. Older Node versions aren't supported, so teams on legacy LTS releases need to upgrade before adopting Koa.

How is Koa's middleware different from Express middleware?

Koa's middleware runs on native async functions instead of Express's callback-based (req, res, next) signature. A Koa handler takes (ctx, next), awaits next() to run downstream middleware, then keeps executing after it resolves — no nested callbacks needed to touch the response on the way back out.

Is Koa actively maintained in 2024?

Koa's README shows live CI status (GitHub Actions) and test-coverage tracking (Codecov) right on the page, which points to an active pipeline rather than an abandoned repo, though the README doesn't list a specific 2024 release date. Its migration guides from v1 to v2 to v3 also show the project has kept moving across major versions.

How do I write async middleware in Koa?

Async middleware in Koa is just a function shaped like async (ctx, next) => { ... }. Do work before await next(), then more after it — that continuation runs once every downstream middleware finishes, making it a natural place to time a request from start to finish.

Does Koa come with built-in middleware like Express does?

Koa ships with zero bundled middleware, unlike Express which includes some conveniences by default. The README states plainly that Koa is not bundled with any middleware — routing, body parsing, sessions, and static file serving all come from separate koa-* packages you add yourself.

What is the Koa context object (ctx)?

The Koa context object, ctx, is created for each incoming request and bundles Koa's Request and Response objects into one place, alongside shortcuts like ctx.body and ctx.type. It also exposes the raw Node req and res objects if you need to drop below Koa's abstraction.

The problem it solves

Callback-based Node middleware (Connect, and Express before ES2017) made 'run code before the handler, then more code after it' awkward — you either nested callbacks or reached for generators, which is what Koa itself used in v1.x. Middleware packages also commonly extended Node's raw request and response objects directly, which caused conflicts when two packages patched the same property differently. Koa's answer is to build the whole stack around async/await and to delegate to, rather than extend, Node's IncomingMessage/ServerResponse.

Who should try it — and who should skip

Teams that want direct control over their middleware stack — and are fine picking a router, a body parser, and error-handling middleware themselves — get the most out of Koa. It also suits developers who already think in async/await and want that to be the framework's native shape, not a callback API wrapped after the fact. Skip it if you want routing, validation, and sane defaults working immediately after npm install, or if your team is stuck on a Node version older than v18.

Source & attribution

Based on the koajs/koa GitHub repository (github.com/koajs/koa), its README, and its published GitHub topics and metadata.

GitHub data · last synced Aug 15, 2026Reviewed by Henry
← Back to TopGit

Want a second opinion on koa?

Ask an AI that can read this page — one click and you get its take on koa.

GitHub