Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/beliven-it/fastify-plugin-loader
A plugin to register an ordered list of plugins (e.g. from a JSON file)
https://github.com/beliven-it/fastify-plugin-loader
fastify js json loader nodejs plugin
Last synced: 24 days ago
JSON representation
A plugin to register an ordered list of plugins (e.g. from a JSON file)
- Host: GitHub
- URL: https://github.com/beliven-it/fastify-plugin-loader
- Owner: beliven-it
- License: mit
- Created: 2020-06-11T14:49:20.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-03-05T11:13:49.000Z (almost 2 years ago)
- Last Synced: 2024-11-16T16:13:36.254Z (about 1 month ago)
- Topics: fastify, js, json, loader, nodejs, plugin
- Language: JavaScript
- Homepage:
- Size: 680 KB
- Stars: 1
- Watchers: 5
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# fastify-plugin-loader
A plugin to register an ordered list of plugins (e.g. from a JSON file)
![Node.js CI](https://github.com/heply/fastify-plugin-loader/workflows/Node.js%20CI/badge.svg)
## Why?
The official [fastify-autoload](https://github.com/fastify/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
```bash
$ npm i --save fastify-plugin-loader
```## Usage
```js
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:
```js
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
```bash
$ npm test
```## Acknowledgements
This project is kindly sponsored by:
[![Beliven](https://assets.beliven.com/brand/logo_pos_color.svg)](https://www.beliven.com)
## License
Licensed under [MIT](./LICENSE)