🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

fastify-plugin

Package Overview
Dependencies
Maintainers
2
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fastify-plugin

Plugin helper for Fastify

2.0.2
Source
npm
Version published
Weekly downloads
3.1M
5.89%
Maintainers
2
Weekly downloads
 
Created

What is fastify-plugin?

The fastify-plugin npm package is designed to facilitate the creation of plugins for the Fastify web framework. It ensures that plugins adhere to specific conventions and are compatible with the Fastify ecosystem. This package helps in encapsulating functionality, adding hooks, decorators, and more, in a way that's easily reusable across different Fastify projects.

What are fastify-plugin's main functionalities?

Plugin Creation

This feature allows developers to create a Fastify plugin. The code sample demonstrates how to use fastify-plugin to decorate the Fastify instance with a new function called 'utility'.

const fp = require('fastify-plugin');

async function myPlugin (fastify, options) {
  fastify.decorate('utility', () => 'something useful');
}

module.exports = fp(myPlugin);

Plugin Options

This feature enables passing options to the plugin, including specifying Fastify version compatibility. The code sample shows how to pass data through options and use it within the plugin.

const fp = require('fastify-plugin');

async function myPlugin (fastify, options) {
  fastify.decorate('usefulData', options.data);
}

module.exports = fp(myPlugin, { name: 'myPlugin', fastify: '3.x' });

Encapsulation

This feature ensures that the plugin does not encapsulate its context, allowing the decorators, hooks, and changes made by the plugin to be available in the parent scope. The code sample demonstrates registering another plugin within a fastify-plugin, ensuring dependencies are managed.

const fp = require('fastify-plugin');

async function myPlugin (fastify, options) {
  fastify.register(require('some-other-plugin'), options);
}

module.exports = fp(myPlugin, { dependencies: ['some-other-plugin'] });

Other packages similar to fastify-plugin

Keywords

plugin

FAQs

Package last updated on 24 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts