In languages like Python and Java, HTTP request handlers are typically defined as classes. HTTP request handler classes tend to suffer from dependency bloat: to instantiate a Python BaseHTTPRequestHandler class
, you need to pass 3 parameters to the constructor, including a server instance. This makes it trickier to test a BaseHTTPRequestHandler in isolation and makes it harder to understand what the framework is doing.
In Express, a request handler is just a function. There’s nothing to instantiate. Express calls your function with 3 parameters: req, res, next. That means you can call your request handler function with fake parameters for testing.