Files
khoa/docs/koa-vs-express.md
Khoajs Sync Bot 1f4bbea3d9
Some checks failed
Node.js CI / build (18.x) (push) Has been cancelled
Node.js CI / build (20.x) (push) Has been cancelled
Node.js CI / build (22.x) (push) Has been cancelled
chore: apply Khoajs naming transformations (upstream sync)
2026-04-17 19:46:56 +00:00

3.7 KiB

Khoa vs Express

Philosophically, Khoa aims to "fix and replace Node", whereas Express "augments Node". Khoa uses promises and async functions to rid apps of callback hell and simplify error handling. It exposes its own ctx.request and ctx.response objects instead of Node's req and res objects.

Express, on the other hand, augments Node's req and res objects with additional properties and methods and includes many other "framework" features, such as routing and templating, which Khoa does not.

Thus, Khoa can be viewed as an abstraction of Node.js's http modules, where as Express is an application framework for Node.js.

Feature Khoa Express Connect
Middleware Kernel
Routing
Templating
Sending Files
JSONP

NOTE: this doesn't mean Khoa is incapable of supporting these features, these features are simply supported by other modules (middleware, plugins, etc.) versus the framework itself.

Thus, if you'd like to be closer to Node.js and traditional Node.js-style coding, you probably want to stick to Connect/Express or similar frameworks. If you want to get rid of callbacks, use Khoa.

As result of this different philosophy is that traditional Node.js "middleware", i.e. functions of the form (req, res, next), are incompatible with Khoa. Your application will essentially have to be rewritten from the ground, up.

Does Khoa replace Express?

It's more like Connect, but a lot of the Express goodies were moved to the middleware level in Khoa to help form a stronger foundation. This makes middleware more enjoyable and less error-prone to write, for the entire stack, not just the end application code.

Typically many middleware would re-implement similar features, or even worse incorrectly implement them, when features like signed cookie secrets among others are typically application-specific, not middleware-specific.

Does Khoa replace Connect?

No, just a different take on similar functionality now that generators allow us to write code with fewer callbacks. Connect is equally capable, and some may still prefer it, it's up to what you prefer.

Why isn't Khoa just Express 4.0?

Khoa is a pretty large departure from what people know about Express, the design is fundamentally much different, so the migration from Express 3.0 to this Express 4.0 would effectively mean rewriting the entire application, so we thought it would be more appropriate to create a new library.

How is Khoa different from Connect/Express?

Promises-based control flow

No callback hell.

Better error handling through try/catch.

No need for domains.

Khoa is barebones

Unlike both Connect and Express, Khoa does not include any middleware.

Unlike Express, routing is not provided.

Unlike Express, many convenience utilities are not provided. For example, sending files.

Khoa is more modular.

Khoa relies less on middleware

For example, instead of a "body parsing" middleware, you would instead use a body parsing function.

Khoa abstracts Node's request/response

Less hackery.

Better user experience.

Proper stream handling.

Khoa routing (third party libraries support)

Since Express comes with its own routing, but Khoa does not have any built-in routing, there are third party libraries available such as khoa-router and khoa-route. Similarly, just like we have helmet for security in Express, for Khoa we have khoa-helmet available and the list goes on for Khoa available third party libraries.