If you need to use an express style middleware you can use one of the two plugins above:

    Remember that middleware can be encapsulated, this means that you can decide where your middleware should run by using register as explained in the .

    Restrict middleware execution to a certain path(s)

    If you need to run a middleware only under certain path(s), just pass the path as first parameter to use and you are done!

    Fastify offers some alternatives to the most commonly used middlewares, such as in case of helmet, for cors and for serve-static.