- Building Enterprise JavaScript Applications
- Daniel Li
- 278字
- 2021-07-23 16:31:25
Choosing a framework
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:
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"