Like what we’re doing? Star us on GitHub!

Can you use fastify instead of express?

GoldStrikeArch
last year
2 2

Hi there!
I really like fastify and I prefer it over express but it seems that payload expect only express app (according to docs), am I correct? Is there a way to use fastify instead of express?

  • jmikrut
    Payload Team
    last year

    Hey @MihailPertsev — thanks for the thought!

    At the moment, we are using many Express-specific middlewares. Each would need to be converted over accordingly to work with Fastify I believe. So this would not be a simple task as far as I know.

    If there is enough demand, it's possible that we could support Fastify in the future. We are about to open a public roadmap, which you will be able to vote on new features and enhancements. We'll add "support other HTTP frameworks" as a roadmap item, and if it garners enough attention, we would definitely build support for it!

    2 replies
  • GoldStrikeArch
    last year

    I think it should not be that complicated in fastify case, because you can use express middlewares in fastify via fastify-express plugin.

  • Ontopic
    last year

    Would love to hear updates when you're gonna try :)

  • yamiteru
    last year

    Why not use uWebSockets? It's much faster than Fastify 🤔

    6 replies
    GoldStrikeArch
    last year

    Yeah, didn't even know about it before your reply!
    It seems that its indeed a "blazing fast" by a large margin (8.5x faster than Fastify). Yet it seems that it lacks an "ecosystem" around it, see for example what fastify can offer out of the box and you can also use express middlawares as well.

    I will play around with uWebSockets.js but what I am afraid of is that this .js project is a just wrapper for "libuv", so the main uWebSockets project which written in C++ can communicate with Node js. So, I can imagine that if you hit some "complexity" you might need to write some C++ code as well 😱

    yamiteru
    last year

    I've used uWebSockets extensively and never had to touch C++. Thanks to being low-level you can do much more with it than you can with Express/Fastify. Middlewares are just an array of async functions that run before the main request handler 🤷‍♂️

    GoldStrikeArch
    last year

    I've used uWebSockets extensively and never had to touch C++. Thanks to being low-level you can do much more with it than you can with Express/Fastify. Middlewares are just an array of async functions that run before the main request handler 🤷‍♂️

    Well, I do not feel pretty comfortable to use "low lvl" abstractions myself, maybe this is the main reason for me to use express/fastify. Can you please provide some repos examples for uWebSockets? And to be honest I am not even sure for what kind of apps this "blazing fast" power would benefit? I mean, I know that any app will be better if your responses would be faster but I just don't know how huge and complex the app should be to see benefits of uWebSockets again Fastify/Express. Also I am not sure about "Thanks to being low-level you can do much more with it than you can with Express/Fastify.", can you please clarify it?

    yamiteru
    last year

    Here are two articles:

    And official examples:

    Well it benefits all apps obviously. Every app benefits from having a smaller bottleneck in serving requests. The more router logic you have and the bigger number of simultaneous connections the more you're gonna benefit from uWebSockets.

    To the last point. From my experience you very often need a plugin of some sort for things like backpressure, middlewares, websockets, etc. and because those plugins are high-level abstractions you never truly know your code and with that a technical debt comes.

    Even tho using uWebSockets might seems tedious at first you quickly find out everything is just functions and getters that output raw data and it's up to you what you're gonna do with them.

    GoldStrikeArch
    last year

    Thanks for the articles, I saw official repo examples but I was asking about "full apps" examples on uWebSockets with that "additional stuff that Express/Fastify cannot do (or can do very poorly)".

    yamiteru
    last year

    I guess you're gonna have to look for them since I cannot give you an access to my private repos.

Open the post
Continue the discussion in GitHub
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More