fastify-plugin-loader

0.0.1 • Public • Published

fastify-plugin-loader

A plugin to register an ordered list of plugins (e.g. from a JSON file)

Node.js CI

Why?

The official fastify.-autoload plugin allows devs to load all plugins stored in a specific folder.

The main issue with this approach is that it's nearly impossible to:

  • define a specific loading order
  • passing configuration options to loaded plugins

Install

$ npm i --save fastify-plugin-loader

Usage

fastify.register(require('fastify-plugin-loader'), {
  basepath: __dirname,
  plugins: [
    'fastify-cors',
    'fastify-sensible',
    ...
    './plugins/example-plugin',
    ['./plugins/another-plugin', {
      option1: 'value',
      ...
    }]
  ]
)

You can also load them from an external JSON (or JS) file:

fastify.register(require('fastify-plugin-loader'), {
  basepath: __dirname,
  plugins: require('./plugins.json')
)

Options

When registering the plugin in your app, you can pass the following options:

Name Description
basepath The reference root path to consider when resolving . or ..
plugins The ordered list of plugin filenames to load (or [filename, opts] tuples).

NOTE: additional options are forwarded to all loaded plugins (and merged with plugin's local options, if provided).

Test

$ npm test

Acknowledgements

This project is kindly sponsored by:

heply

License

Licensed under MIT

Package Sidebar

Install

npm i fastify-plugin-loader

Weekly Downloads

1

Version

0.0.1

License

MIT

Unpacked Size

10.4 kB

Total Files

11

Last publish

Collaborators

  • beliven.dev