Migrate Your Express Application to Fastify

This page summarizes the projects mentioned and recommended in the original post on dev.to

SaaSHub - Software Alternatives and Reviews
SaaSHub helps you find the best software and product alternatives
www.saashub.com
featured
  • pino

    🌲 super fast, all natural json logger

    Fastify comes with Pino by default, but logging must be enabled for it to work:

  • SaaSHub

    SaaSHub - Software Alternatives and Reviews. SaaSHub helps you find the best software and product alternatives

    SaaSHub logo
  • node-url-shortener

    Fastify offers many additional features that we couldn't cover in this series, so check out the Fastify official documentation to learn more. Also, you can find all the code samples we used in this GitHub repository.

  • fastify-express

    Express compatibility layer for Fastify

    As mentioned in part 2 of this series, using the @fastify/express plugin is the quickest way to get your existing Express application working with Fastify. The plugin adds full Express compatibility to Fastify so that you can easily use any Express middleware — or even an entire Express application — with your Fastify instance, and it will just work with no changes required.

  • point-of-view

    Template rendering plugin for Fastify

    Since we've migrated our only application route that renders templates, the above lines are no longer needed and can be safely deleted. But you now need to configure Fastify to render the Pug template through the @fastify/view plugin. It decorates the Reply interface with a method that we'll then use to render the template.

  • ajv

    The fastest JSON schema Validator. Supports JSON Schema draft-04/06/07/2019-09/2020-12 and JSON Type Definition (RFC8927)

    Since Fastify supports schema validation with Ajv, the validate module is no longer required on the /shorten route, and we can specify the JSON schema directly on the route. The controllers for both routes will largely remain the same, except that the res parameter is renamed to reply as before:

  • fastify-static

    Plugin for serving static files as fast as possible

    We can replace this middleware with the @fastify/static plugin, which you can install through the command below:

  • fastify-helmet

    Important security headers for Fastify

    helmet -> @fastify/helmet.

  • fastify-cors

    Fastify CORS

    cors -> @fastify/cors.

  • winston

    A logger for just about everything.

    Our Express application uses Winston and Morgan for logging HTTP requests.

  • Jade

    Pug – robust, elegant, feature rich template engine for Node.js

    To illustrate the process of migrating from Express to Fastify, we have prepared a demo application. This application utilizes Express, Mongoose, and Pug to create a URL Shortener app as follows:

  • telescope.nvim

    Find, Filter, Preview, Pick. All lua, all the time.

    {"level":"info","time":"2023-05-08T08:09:43.047Z","pid":920874,"host":"fedora","reqId":"req-1","req":{"method":"POST","url":"/shorten","hostname":"localhost:3000","remoteAddress":"127.0.0.1","remotePort":60582},"msg":"incoming request"} {"level":"debug","time":"2023-05-08T08:09:43.058Z","pid":920874,"host":"fedora","msg":"https://github.com/nvim-telescope/telescope.nvim#themes shortened to mB5Ke86"} {"level":"info","time":"2023-05-08T08:09:43.060Z","pid":920874,"host":"fedora","reqId":"req-1","res":{"statusCode":200},"responseTime":12.570792019367218,"msg":"request completed"}

NOTE: The number of mentions on this list indicates mentions on common posts plus user suggested alternatives. Hence, a higher number means a more popular project.

Suggest a related project

Related posts

  • Advanced Fastify: Hooks, Middleware, and Decorators

    4 projects | dev.to | 31 May 2023
  • Getting Started with Fastify for Node.js

    4 projects | dev.to | 5 May 2023
  • From Vercel to Monolith, improving API speeds

    2 projects | dev.to | 25 Jun 2024
  • 5 Node.js security code snippets every backend developer should know

    1 project | dev.to | 29 Feb 2024
  • Google OAuth2 with Fastify + TypeScript From Scratch

    3 projects | dev.to | 5 Nov 2023