Express vs. Fastify — How to Choose a Framework

Mitchel Sarauer
8 min readJun 28, 2021

** I wrote this article specifically targeted towards junior developers who are just getting started in the world of web development**

As a junior web developer myself, I find the choice of libraries and frameworks can seem both overwhelming and exciting as you are getting started. There are two parts to this article. In the first section, I lay out my opinion on general guidelines to help you, a junior developer, decide on the path to take between the plethora of options out there. In the second part, I will take a look at a comparison of two popular Node.js frameworks — Express and Fastify.

Part 1: How to decide?

My thoughts

In a way, my initial path in web development was decided for me. I am currently nearing the completion of a 12 week long Web Development Bootcamp that has laid the foundation for my career by choosing the technologies I learn for me. But as I move forward beyond the Bootcamp, I have some decisions to make: Do I keep honing my skills in the specific tech stack that was taught to me during this Bootcamp, or do I spend some time learning a new language/library/framework?

Thinking about these questions recently, took me on a dive down a rabbit hole. Some of my recent Google searches include: “What tech stack is the best to learn in 2021?”, “Should I learn ‘x, y, or z’ framework?”, “How to decide which technology to learn?”. With so many opinions out there, I had to make up my mind on my own and so, I came up with the following list of guidelines to help with this decision-making process:

1. The number one factor. In my opinion, the first thing you should be asking yourself is whether a specific stack choice will fit your project’s needs. Just because you read online that the “MERN” stack is the stack of choice these days, does not mean that it is the right stack of choice for your needs. Ask around, “will this work well/work at all for creating X project?” What I learned is that there really isn’t a web development technology that is the best for every single application.

2. Are you looking to get hired? If so, maybe this should actually be the number one consideration. If your primary reason for learning web development is to get a job, use this to inform your decision. Take a look at the job postings in your market, as well as specific postings from companies you would like to work for. What stack do they use? Sure, the shiny, feature-rich, new tech may seem fun to learn and start applying to projects, but if your main goal is to get hired, maybe stick to something tried and true first before venturing into the niche markets.

3. Use the community. From my short time in the web development industry, one thing I am already sure about is that web developers have created a great community of people who are always willing to answer questions. Seriously, I am already so appreciative of those people answering obscure questions on StackOverflow. I truly wonder if I will ever face a problem that doesn’t have some sort of help out there already. But, to get back on topic — take advantage of these communities, like Reddit or StackOverflow, and watch videos on Youtube. There is a lot of information and opinions out there already on the best stack to choose for your use case. The opinions will vary, but I’ve found this super useful as I begin my career.

4. If you don’t know the basics, start there. This is another contender for the number one point in this section… It probably goes without saying, but if you don’t already know the basics of Javascript, HTML, or CSS, I would highly recommend starting there before venturing into more specific frameworks. This is where we started in Bootcamp, and I truly believe this will make learning those newer, fancier technologies a great deal easier.

5. Follow the trends. State of JS and the State of the Octoverse both have a large amount of information on where the industry is at and where it is heading. You probably don’t want to learn something that is on its way out (unless you have a very specific need), and you also don’t want to be learning something where the general sentiment in the industry is negative. Apart from this, these websites are just super interesting reads about the industry in general.

6. Have fun! Whatever you pick, make sure you enjoy doing it. You’ll be much better off picking something you like doing over something you are dreading to sit down and work with every day.

Summary

One blog post I fell upon when researching this topic stuck with me: ‘Happiness is a Boring Stack’. The message I took away is that you should maybe not always fall for the hype. As you research this topic on your own, you’ll read that ‘x framework is dead’, or ‘why this framework is the React killer’. But maybe the best plan for you is to pick something near the top of one of the web development trend websites and work hard at getting really good at that thing. This likely won’t work for everyone; some people just love using cutting-edge stuff, but for me, this is the way to go. Once I can hammer out projects with the stack of my choice, and it becomes almost second nature or ‘boring’, then I will venture into the new and shiny to dabble a bit.

Part II — Express vs Fastify

Now that we’ve gone through my thoughts on choosing between tech stack options, I wanted to give one specific comparison — Express vs Fastify for a back-end web framework.

Express

What is Express?

Weekly downloads 16.9M+ | 53k+ Github stars

Express is by far the most popular web framework for Node.js. It was first released on November 16, 2010, by TJ Holowaychuk. If you have ever heard of the popular MERN, MEAN, or MEVN stacks, Express is the ‘E’ from these acronyms. It is used by many big sites such as Fox Sports, PayPal, Uber, and IBM to name a few.

A simple server in Express

The Express website gives an example of essentially the simplest Express app you can create:

const express = require(‘express’)const app = express()const port = 3000app.get(‘/’, (req, res) => {res.send(‘Hello World!’)})app.listen(port, () => {console.log(`Example app listening at http://localhost:${port}`)})

With these few lines of code, a server is running and listening on port 3000 for connections. Any request to the root URL (/), the app will respond with “Hello World!”. It is that simple, and it is no wonder why Express took off the way it had.

Express pros

  • Extensive documentation already exists
  • Community backing (answers to most questions are easily found)
  • Loads of plugins
  • Supports many (14+) template engines
  • Widely used in industry

Express Cons

  • Over two years since the last update
  • Relatively slower compared to newer alternatives

Fastify

What is Fastify?

Weekly downloads 216k+ | 19k+ Github stars

When searching for alternatives to Express for this article, I found many recommendations for Fastify. Fastify was first released on Oct. 17, 2016, and was created by Matteo Collina and David Mark Clements. From the Fastify website, 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.”

Fastify makes it easy to migrate from an Express app using fastify-express, which adds full express compatibility to Fastify. And while not as widely used in the industry yet, Microsoft and Car2Go are two major organizations listed as users of Fastify.

A simple server in Fastify

Similarly to the Express ‘Hello World’ example, here is a quick server setup in Fastify:

const fastify = require(‘fastify’)({logger: true})fastify.get(‘/’, (request, reply) => {reply.send({ hello: ‘world’ })})fastify.listen(3000, (err, address) => {if (err) throw err})

Also seems super simple to get up and running!

Benchmark Comparison

One of the main reasons that Fastify is so popular is its claim that it was built from the ground up to be as fast as possible. The Fastify website demonstrates this with benchmark testing vs other well known Node.js web frameworks:

As you can see, Fastify is fast. Their benchmarks show that it performs over 5x as fast as Express when looking at req/sec.

Fastify Pros

  • Blazing fast compared to other popular Node frameworks
  • Very little overhead added to the Node.js core
  • Actively maintained
  • Fully encapsulated plugins (avoids cross-dependency requirements)

Fastify Cons

  • Not widely used in the industry yet
  • Less documentation exists
  • Less community support for debugging

Summary

When I set out to start researching this article, my first thoughts were that ‘of course a newer, more optimized framework will beat out the older and more clunky framework.’ But with more thought and more research into the topic, I believe my mind has been changed.

While the general opinion in the industry seems to be that Fastify has generally made improvements over Express in many areas, my opinion is that a new developer should, for the most part, just stick with Express (at least for the early parts of their career). This may be a boring answer, but in my opinion, it will likely lead to a more successful and well-rounded career as a web developer. For individual projects, ask yourself whether the increase in speed provided by Fastify is going to make a significant difference in your project. I bet, for the majority of projects, the answer to this question will be no.

All that being said, web development is also an industry that demands relevancy. So as you advance in your career, stay relevant — read articles and follow the latest trends. One day, Express will be supplanted as the leader, and you should be prepared to move on from it as well.

Happy coding! :)

Resources

https://www.fastify.io/

http://expressjs.com/

https://codersera.com/blog/learn-express-js/

https://www.expatsoftware.com/Articles/happiness-is-a-boring-stack.html

https://github.com/freeCodeCamp/chapter/issues/80

https://www.nearform.com/blog/how-fastify-has-become-the-latest-openjs-foundation-incubating-project/

https://pawelgrzybek.com/from-express-to-fastify-in-node-js/

https://survivejs.com/blog/fastify-interview/

--

--