It’s Time to Replace Express with Fastify for Your Next Node.js API

Released in 2016, Fastify isn’t a new project but it has been actively maintained and with 21.5k stars on GitHub, it has gathered quite the following. Based on its stats, it’s easy to see why:Not only is it 5x faster than Express, you can still use the…


This content originally appeared on Bits and Pieces - Medium and was authored by Dominic Tobias

Released in 2016, Fastify isn’t a new project but it has been actively maintained and with 21.5k stars on GitHub, it has gathered quite the following. Based on its stats, it’s easy to see why:

Not only is it 5x faster than Express, you can still use the Express middleware you’re used to, so it’s simple to pick up. The API is also typed, which is something we have come to expect from modern JavaScript libraries.

Another nice feature is that it supports JSON Schema to validate input and output of HTTP handlers (more on that later).

Installation

First we will install fastify, middie, and some commonly used middleware:

yarn add fastify middie cors frameguard x-xss-protection

Server setup

To give you an idea of using the optional JSON Schema, let’s validate and strongly type a querystring so that it must contain postcode:

Here you can see that we’re not only using TypeScript, but also additional JSON schema to validate and ensure that our API output is exactly what we want it to be.

On line 14, we see that our API looks very almost identical to what we would typically expect to see from an Express API. This makes it easy for Express developers to quickly jump over to Fastify and stay productive. So it’s an easy replacement with a great performance boost!

Build Micro Frontends with components

Microfrontends are a great way to speed up and scale app development, with independent deployments, decoupled codebases, and autonomous teams.

Bit offers a great developer experience for building component-driven Micro frontends. Build components, collaborate, and compose applications that scale. Our GitHub has over 14.5k stars!

Give Bit a try →

An independently source-controlled and shared “card” component (on the right, its dependency graph, auto-generated by Bit)

Learn more


It’s Time to Replace Express with Fastify for Your Next Node.js API was originally published in Bits and Pieces on Medium, where people are continuing the conversation by highlighting and responding to this story.


This content originally appeared on Bits and Pieces - Medium and was authored by Dominic Tobias


Print Share Comment Cite Upload Translate Updates
APA

Dominic Tobias | Sciencx (2021-12-29T07:36:18+00:00) It’s Time to Replace Express with Fastify for Your Next Node.js API. Retrieved from https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/

MLA
" » It’s Time to Replace Express with Fastify for Your Next Node.js API." Dominic Tobias | Sciencx - Wednesday December 29, 2021, https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/
HARVARD
Dominic Tobias | Sciencx Wednesday December 29, 2021 » It’s Time to Replace Express with Fastify for Your Next Node.js API., viewed ,<https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/>
VANCOUVER
Dominic Tobias | Sciencx - » It’s Time to Replace Express with Fastify for Your Next Node.js API. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/
CHICAGO
" » It’s Time to Replace Express with Fastify for Your Next Node.js API." Dominic Tobias | Sciencx - Accessed . https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/
IEEE
" » It’s Time to Replace Express with Fastify for Your Next Node.js API." Dominic Tobias | Sciencx [Online]. Available: https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/. [Accessed: ]
rf:citation
» It’s Time to Replace Express with Fastify for Your Next Node.js API | Dominic Tobias | Sciencx | https://www.scien.cx/2021/12/29/its-time-to-replace-express-with-fastify-for-your-next-node-js-api/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.