Nowadays most developers uses express by default to build a new Node.JS app. It's is popular, easy to use and even Nest.JS uses it behind the scenes.
But if you take a look at the Fastify docs, you’ll see that it works quite differently from Express:
- Fastify uses fast-json-stringify by Matteo Collina with built-in functions based on schemas for serialize objects too fast
- Fastify uses a radix tree for routing - a compact and optimized tree built during server setup.
- It’s minimalist, with a strong focus on core performance
- Native validation using JSON Schema via Ajv
Express working as well but for optimization...
- Express uses JSON.stringify for serialize objects
- Linear routing based on route definition
- Minimalist but depends on directly middlewares
- No native validation
Below, you can see two files with simple implementations using Express and Fastify.I also ran a quick benchmark with Autocannon, and here are the results:
Express might feel comfortable, but give Fastify a try at least once.
Ref:
https://fastify.dev/docs/v2.15.x/Documentation/Server/
https://ankitpandeycu.medium.com/unleashing-the-potential-of-radix-tree-35e6c5d3b49d
https://www.npmjs.com/package/fast-json-stringify
https://fastify.dev/benchmarks/
Top comments (1)
Been cool seeing steady progress like this - always makes me wanna actually try new stuff instead of just doing what I already know.