Express Vs Fastify

Why Fastify is a better Nodejs framework for your next project compared to Express

Vishal Sharma
3 min readAug 10, 2021

ExpressJS vs Fastify: What are the differences?

Developers describe ExpressJS as “Sinatra inspired web development framework for node.js — insanely fast, flexible, and simple”. Express is a minimal and flexible node.js web application framework, providing a robust set of features for building single and multi-page, and hybrid web applications. On the other hand, Fastify is detailed as “Fast and low overhead web framework, for Node.js”. Fastify is a web framework highly focused on speed and low overhead. It is inspired from Hapi and Express and as far as we know, it is one of the fastest web frameworks in town. Use Fastify can increase your throughput up to 100%.

ExpressJS and Fastify can be categorized as “Microframeworks (Backend)” tools.

Some of the features offered by ExpressJS are:

  • Robust routing
  • HTTP helpers (redirection, caching, etc)
  • View system supporting 14+ template engines

On the other hand, Fastify provides the following key features:

  • 100% asynchronous: all the core is implemented with asynchronous code, in this way not even a millisecond is wasted.
  • Highly performant: as far as we know, Fastify is one of the fastest web frameworks in town, depending on the code complexity we can serve up to 20000 request per second.
  • Extendible: Fastify is fully extensible via its hooks, plugins and decorators.

ExpressJS and Fastify are both open source tools. ExpressJS with 44.6K GitHub stars and 7.48K forks on GitHub appears to be more popular than Fastify with 11.2K GitHub stars and 690 GitHub forks.

According to the StackShare community, ExpressJS has a broader approval, being mentioned in 854 company stacks & 788 developers stacks; compared to Fastify, which is listed in 5 company stacks and 7 developer stacks.

This is a typical example of a node application:

Node with express framework

In the code snippet above, we included Nodejs express module, which was used to create the express server.

Express Overview

Express is a minimal and flexible Node.js web application framework that provides a robust set of features to develop web and mobile applications. It facilitates the rapid development of Node based Web applications. Following are some of the core features of Express framework −

  • Allows to set up middlewares to respond to HTTP Requests.
  • Defines a routing table which is used to perform different actions based on HTTP Method and URL.
  • Allows to dynamically render HTML Pages based on passing arguments to templates.

Introducing Fastify

Fastify is not just another framework, it is one of the fastest web frameworks out there. What makes Fastify a great choice for me is the fact that it is:

  1. Open-sourced
  2. Developer friendly
  3. It’s highly performant
  4. It comes with a logger too

An efficient server implies a lower cost of the infrastructure, a better responsiveness under load and happy users. How can you efficiently handle the resources of your server, knowing that you are serving the highest number of requests possible, without sacrificing security validations and handy development?

Enter Fastify. Fastify is a web framework highly focused on providing the best developer experience with the least overhead and a powerful plugin architecture. It is inspired by Hapi and Express and as far as we know, it is one of the fastest web frameworks in town.

Node with fastify framework

Let’s go through the working parts of the snippet above

  • Firstly, we enabled fastify logger. By default, it is disabled.
  • Next, we assigned a port number for our application. However, when deploying to production, it’s recommended you use process.env.PORT.
  • Next, we created our first route! You notice that our controller function is synchronous. We will see more of that when we write our controller.
  • Finally, we start the server on port 3000.

Save and then run this command on your terminal to start the server.

--

--

Vishal Sharma

Hello i am vishal sharma working as MEAN stack developer having 4 years of experience. Love to help needy people, learn new things, explore new places.