Hapi vs Koa vs Express

Node.js has various frameworks, each of which is catered to the varying demands of users and developers. This article will give a comparison between the three major Node.js frameworks, ExpressHapi, and Koa.

In this comparison, we will look at the differences between the three frameworks, their histories, advantages and disadvantages, popularity, support and performance.

For more background on the frameworks, check out the following articles to get a more in depth look before we begin:

  • Introduction to Hapi.js framework
  • Introduction to Koa.js framework
  • Introduction to Node.js

1. Framework histories

Before we start our in-depth comparison of each framework, let’s take a look at how they got started.

1.1. Hapi.js

Hapi.js was created by the mobile team at Walmart Labs — led by Eran Hammer to handle their traffic for events like Black Friday, since it’s one of the busiest shopping days in the U.S. calendar.

Hapi’s initial commit was made on August 5th, 2011 and after 5,619 commits, it is currently at version 20.0.0. It was originally built using the Express framework before challenges arose that drove Walmart to make Hapi, its stand-alone framework.

1.2. Koa.js

Koa’s initial commit was made on August 17th, 2013 by TJ Holowaychuk. The framework was built by the team behind express with the aim of making it smaller, more expressive, and robust. Koa.js is currently at version 2.13.0 with 1,086 commits.

Koa.js is also known for having a smaller footprint compared to other frameworks.

1.3. Express.js

The Express framework is the oldest of the three. Its initial commit was made by TJ Holowaychuk on June 26th, 2009 and its first release was on the 2nd of January 2010 after around 660 commits.

The two main contributors at the time of its first release were TJ Holowaychuk and Ciaron Jessup. Express.js is currently at version 4.17.1 after 280 releases and 5,592 commits.

2. Framework popularity

All these frameworks are widely used by developers worldwide, but still, one might need to know which framework is the most popular. Our popularity comparison will be based on statistics from GitHub and npm

2.1. Hapi.js

Hapi.js’s GitHub repository has 12.7k stars, 205 contributors, 1.3k forks, and 332 releases.

According to npm, 1,470 packages depend on Hapi.js.

2.2. Koa.js

Koa.js’s GitHub repository has 29.9k stars, 218 contributors, and 2.8k forks.

According to npm, 4,678 packages depend on Koa.js.

2.3. Express.js

Express.js’s GitHub repository has 50k stars, 205 contributors, 8.3k forks, and 280 releases.

According to npm, 45,743 packages depend on Express.js.

3. Creating a server

In this section we will look at how the frameworks differ in creating a server. Unlike Hapi, both Koa and Express use a similar logic to create a server.

In Express, you first import the express module, then, instantiate the module and store it in a variable. Then use its listen method to start a server at a certain port.

Let’s see a code example to illustrate this.

Make sure to run

npm install express

to install the express module.


const express = require('express');
const app = express();

app.listen(2400, () => {console.log('Server started at port 2400')});

As we mentioned earlier, Koa uses the same logic as Express. We import the Koa module, instantiate, store it in a variable, and then use its listen method to start the server.

The code snippet below shows how we start a server using Koa.js.

First run

npm install koa

to install the koa module.


const koa = require('koa');
const app = new koa();

app.listen(2400, () => {console.log('Server started at port 2400')});

Now let’s look at how Hapi stands out. In Hapi, we import the hapi module, then, instead of instantiating the module, we use its server method to create a server by passing an object containing the port and host name.

Then we use the start method to start the server. Let’s see a code example.


npm install @hapi/hapi

to install hapi module.


const hapi = require('@hapi/hapi');
const server = hapi.server({
    port: 3000,
    host: 'localhost'

console.log('Server running on %s', server.info.uri);

4. Framework advantages and disadvantages

In this section we are going to highlight some of the advantages and disadvantages of each framework.

4.1. Hapi.js


  1. Hapi enables one to build a scalable web application or API.
  2. Hapi uses plugins which breaks applications in to smaller pieces thus helping with scaling.
  3. Hapi provides a deeper control over request handling through the use of context.
  4. Hapi provides input/output validation, routing and caching, hence making it a good choice for building REST APIs.
  5. Hapi provides good plugins such as YarGood, and Catbox, etc.


  1. Refactoring in Hapi is manual.
  2. Endpoints must be created and tested manually.
  3. It restricts developers by using Hapi specific plugins and modules which are not compatible with other frameworks.

4.2. Koa.js


  1. Koa has a small footprint (about 600 lines of code) therefore making it very light weight.
  2. Koa uses try/catch which improves error handling.
  3. Koa has a cleaner and more readable asynchronous code.
  4. Koa does not use callbacks hence facilitating upstream and downstream flow of controls.
  5. Refactoring larger code bases in Koa is easier due to modularization.


  1. Koa has a relatively small community.
  2. It is not compatible with Express middleware.
  3. Koa uses ES6 generators which are not compatible with middleware from other frameworks.

4.3. Express.js


  1. Express has a large community.
  2. Express is simple, flexible, and scalable.
  3. Express is fully customizable.
  4. It is easy to integrate third party services and middleware.
  5. Express has a low learning curve.


  1. Express requires a lot of manual labor since endpoints, middleware, etc. need to be created and tested manually.
  2. Refactoring larger code bases is very challenging.

5. Framework performance

In this section, we will compare the frameworks based on the number of requests that a hello world server can handle in one second.

Hapi.js handles 29,998 requests per second while Express handles 38,510 requests per second.

Koa.js seems to be best in terms of performance since it handles 50,933 requests per second.

6. Choosing the right framework for your project

6.1. Why choose Express.js

Express provides a wide range of functionalities for developing web applications such as single/multi-page applications and even hybrid applications.

Express is also easy to test due to its middleware and routes that modularize projects.

Express.js is also closer to Node.js when compared to the other frameworks, it is only a thin layer to Node.js, making it the best for building applications that require the best performance.

6.2. Why choose Koa.js

Koa.js was created to be better than Express, therefore, it can do all that Express can do and more. From our performance test, we saw that Koa performs the best since it can handle more requests per second.

This makes it a better choice for web applications and APIs that serve many clients at a time.

6.3. Why choose Hapi.js

Hapi.js has almost the same capabilities as the other frameworks but its plugin feature is what makes it unique when it comes to selecting frameworks to use.

Hapi has a wide variety of plugins that make it a little bit easier to build APIs with since almost every common task such as routing, logging, caching, and authentication etc. have built-in plugins that have been tested.

Below are some other points that would help when choosing the right framework for a project:

  1. Efficiency demand of the application.
  2. The cost of the project.
  3. Modules available.
  4. The type of project.
  5. Scalability.

7. Summary

In this article we have done a comparison of the three major Node.js frameworks. We have gone through their histories, popularity, advantages and disadvantages, performance and created a server with each one.

With that, a developer can now choose the framework which best satisfies his/her needs for their application.

Related posts:

How To Secure Your Web App With HTTP Headers
How to Prevent Cross-Site Scripting in Node.js
Introduction to Sequelize ORM for Node.js
Documenting a Node.js REST API using Swagger
Most Useful Node.js Packages
Getting Started with the Quasar Framework
Build a Ticketing App with Adonis.js and Vue.js
Creating a Real Time Chat App using React and Socket IO with E2E Encryption
Debugging a Node.js app running in Docker using Nodemon and the Docker extension
Building a Simple Cryptocurrency Blockchain using Node.js
Uploading Files using Formidable in a Node.js Application
How to Create a Simple REST API using TypeScript and Node.js
Open-source packages & Code Security using NPM
Node.js vs. PHP – Which is better for Backend development?
Getting Started With Axios In Nuxt
Generating Authentication Token for Agora Applications
Creating Secure Password Resets With JSON Web Tokens
Getting Started with Node.js Module
How to Implement Caching using Adonis.js 5
Node.js applications following an MVC architecture
Getting Started with Node.js 15
JavaScript Particles Effect with tsParticles
Breaking Down MEAN vs MERN Stacks
Basics of SSH and Building an Application in Node.js
Testing Node.js Applications
Node.js versus Next.js - A React Approach
How to build a GraphQL Server Using Node.js
How To Build A Skin For Your Web App With React And WordPress
Better Error Handling In NodeJS With Error Classes
Creating Secure Password Flows With NodeJS And MySQL
Building A Pub/Sub Service In-House Using Node.js And Redis
Getting Started with HTTP/2 in Node.js