How to write a good plugin

    Need some inspiration? You can use the label “plugin suggestion” in our issue tracker!

    Fastify uses different techniques to optimize its code, many of them are documented in our Guides. We highly recommend you read to discover all the APIs you can use to build your plugin and learn how to use them.

    Do you have a question or need some advice? We are more than happy to help you! Just open an issue in our help repository.

    Once you submit a plugin to our , we will review your code and help you improve it if necessary.

    Documentation

    You can license your plugin as you prefer, we do not enforce any kind of license.
    We prefer the because we think it allows more people to use the code freely. For a list of alternative licenses see the OSI list or GitHub’s .

    Examples

    Always put an example file in your repository. Examples are very helpful for users and give a very fast way to test your plugin. Your users will be grateful.

    It is extremely important that a plugin is thoroughly tested to verify that is working properly.
    A plugin without tests will not be accepted to the ecosystem list. A lack of tests does not inspire trust nor guarantee that the code will continue to work among different versions of its dependencies.

    We do not enforce any testing library. We use since it offers out-of-the-box parallel testing and code coverage, but it is up to you to choose your library of preference.

    Code Linter

    We use since it works without the need to configure it and is very easy to integrate into a test suite.

    It is not mandatory, but if you release your code as open source, it helps to use Continuous Integration to ensure contributions do not break your plugin and to show that the plugin works as intended. Both CircleCI and are free for open source projects and easy to set up.
    In addition, you can enable services like Dependabot or , which will help you keep your dependencies up to date and discover if a new release of Fastify has some issues with your plugin.

    Let’s start!

    Awesome, now you know everything you need to know about how to write a good plugin for Fastify! After you have built one (or more!) let us know! We will add it to the section of our documentation!

    If you want to see some real world examples, check out:

    • point-of-view Templates rendering (ejs, pug, handlebars, marko) plugin support for Fastify.
    • Fastify MongoDB connection plugin, with this you can share the same MongoDB connection pool in every part of your server.
    • Multipart support for Fastify.
    • Important security headers for Fastify.