DEV Community

Cover image for Why should I prefer Fastify to Expressjs?

Why should I prefer Fastify to Expressjs?

Manuel Spigolon on April 21, 2021

"Why should I prefer Fastify to Expressjs?" A lot of people ask me this question over and over again, so I would like to share why I pre...
Collapse
 
nirnejak profile image
Jitendra Nirnejak • Edited

I think the article provides a very good case for using Fastify over Express.js, lot of good points, If someone wants to get a bit more technical details and code example on the subject I would suggest reading this - Express.js vs Fastify - In-Depth Comparison of Node.js Frameworks

Collapse
 
eomm profile image
Manuel Spigolon

Nice article tho!

Collapse
 
annouar profile image
Annouar

Hey ! Thanks a lot for your feedback.

I personally would love to try Fastify and play with it. Honestly, I could even use it for my next production project (I am talking about pure Falsify, not Nest + Falsify).

Nevertheless, I regret the lack of serious starter or boilerplate for production-ready fastify project, as you can find on Nest, Koa, Express, ...

Collapse
 
eomm profile image
Manuel Spigolon

I agree on using pure Fastify: this avoids a lot of useless headache for what I saw on SO - a lot of unanswered questions.

I regret the lack of serious starter or boilerplate for production-ready fastify project

Spoiler: we are working on it!

Collapse
 
sgtino profile image
Stefano Giraldi

I regret the lack of serious starter or boilerplate for production-ready fastify project

Spoiler: we are working on it!

Great news!
I started a prototype project to build my code template for production-ready fastify project. It's available here (I will be honored to have some feedback) :-)

@eomm It's possible to follow the development of your project?

Thread Thread
 
eomm profile image
Manuel Spigolon

Not yet, but it will be possible in the near future 👍

Collapse
 
sarajohn130 profile image
sara john • Edited

All of your doc links are broken.

When you say "So, adding a middleware in expressjs will affect all the requests, even if not necessary.", you can add middleware just to specific routes: see "Router-level middleware" in the docs: expressjs.com/en/guide/using-middl...

Can you expand on the monkey patching part with specific examples?

Collapse
 
eomm profile image
Manuel Spigolon

Thanks, links fixed.

Can you expand on the monkey patching part with specific examples?

It is in the source code:

github.com/expressjs/express/blob/...

Here a better video: youtube.com/watch?v=imw7bIjODr0

Collapse
 
sarajohn130 profile image
sara john

Your first doc link is still broken: link

You should add that express source code link to the article.

And how is Fastify builidng on top of http.ClientRequest not monkey patching? Express builds on top of http.IncomingMessage, how is this monkey patching? Isn't building on top of something inherently monkey patching as changing that underlying thing will change everything on top of it?

Collapse
 
hello10000 profile image
a

how long have you been working as a dev, & how much do you need to know to be able to build a framework like this

Collapse
 
eomm profile image
Manuel Spigolon

I'm contributing to Fastify since 2019 and I think to build a framework like this one you need to know how Node.js works under the hook. There is a lot of prototype inheritance to implement the encapsulation system that is not trivial