NO, you most probably don’t need Express in your Node.js REST API
Express
Express is the simple, well documented and well supported, best sponsored, most downloaded… Web Framework in the Node.js ecosystem.
If you search for a “hello world” HTTP server example in node.js, you will usually find out something like this:
Yes, it feels magic, and we all love it!!!
REST APIs
In today’s enterprise software architectures, REST based APIs/services continue to play a fundamental role, because the HTTP protocol is still massively used as an external and internal communication protocol.
This means, software engineers will most likely prefer to implement the next “service” using a REST API instead of a “queue or event” based approach.
With the adoption of the best “micro-services design” patterns, REST APIs tend to be tiny, stateless, highly decoupled…, usually in charge of atomic business work-flows. This means, commonly multiple API endpoints are invoked to satisfy even the simplest customer interaction with our application features.
Yes, REST APIs have to be fast, REST APIs are required to be fast!
Also, more sophisticated architectures now rely on API-Gateways (like fast-gateway) as a main “app” entry point, where the majority of the non-functional requirements are performed before the request is even proxied to the target REST API. Usually, the following aspects are handled in this level:
- SSL Termination
- Logging
- Load Balancing
- Authentication & Authorization
- Content Negotiation
- Caching
- Content Compression
- Rates Limit
- …
Yes, REST API endpoints are very stupid nowadays!
However, Express is too heavy and slow
Express is great, fully featured…, but is also too heavy and slow for minimalist use cases, such as RESTful micro-services commonly are.
Latest express version (4.16.3) depends of other 30 direct modules, the complete production dependency tree is about 50 modules.
Latest express version execution time is too slow for minimalist use cases. See how it compares to other Node.js Frameworks:
https://github.com/the-benchmarker/web-frameworks
The previous measurements do not only show that express is slow, it means that you need double CPU utilization to perform simple operations, … ultimately causing a considerable impact on your monthly billing; although AWS, GCloud, Azure… might be happy $$$ ;)
Conclusion
In the Node.js ecosystem, there are plenty of flavours when it comes to REST oriented development frameworks. Those are there for a reason.