At a minimum, we want a basic router; at most, we want a web framework. In this section, we will focus on four of the most popular frameworks: Express, Koa, Hapi, and Restify:
| Name | Website | First released | GitHub stars | Description |
| Express | expressjs.com | Jan, 3 2010 | 39,957 |
"Fast, unopinionated, minimalist web framework for Node". Express is a thin routing layer above Node's native http module, with support for templating and middleware (functions that preprocess the request object before it is passed to the handler). Express has been around the longest and is the most popular framework for Node.js. We will use Express as the benchmark from which comparisons with other libraries will be made. |
| Koa | koajs.com | Nov, 8 2013 | 22,847 | Created by TJ Holowaychuk, the same developer behind Express. It is similar to Express but uses async functions instead of callbacks. |
| Hapi | hapijs.com | Aug, 21 2012 | 9,913 |
While Express is minimalistic, Hapi ships with many built-in features, such as input validation, caching, and authentication; all you have to do is specify your settings in the configuration object for that route. Like middleware for Express, Hapi has a request life cycle and extension points where you can process the request or response objects. Hapi also supports a plugin system that allows you to split your app into modular parts. |
| Restify | restify.com | May, 6 2011 | 8,582 | REST framework for providing microservices APIs. It is essentially Express but without the templating parts. It supports DTrace, which allows you to find out the amount of resources (for example, memory, CPU time, filesystem I/O, and bandwidth) used by a process. |
For basic features such as routing, all of these frameworks are more than capable. They differ only in their philosophy and community support.
Express is, without a doubt, the most popular and has the most community support, but it requires a lot of configuration and extra middleware just to get it out of the box. On the other hand, Hapi's configuration-centric philosophy is very interesting, because it means we don't have to change our code or update 10 different middleware, even when the feature code is changed and optimized. It's configuration-as-code, which is a nice philosophy to follow.
However, when we develop our frontend application with React, we may later decide to use more advanced features, such as Server-Side Rendering (SSR). For these, we need to ensure that the tools and integrations we employ are widely used, so that if we run into any trouble, there'll be a large group of developers out there who have faced and resolved those issues. Otherwise, we may waste a long time looking at that source code to figure out a simple problem.
So although Hapi might technically be a better choice in theory, we will use Express because it is more popular and has a lot more community support.
$ git add -A && git commit -m "Handle malformed/non-JSON payloads for POST /user"