f423c50d68ab53747cb68bd178e40d48b5e9237c
Plugin Host
A lightweight, event-driven plugin host system for Node.js applications.
Features
- Dynamic Plugin Loading: Load plugins at runtime from a local directory
- Plugin Registry: Automatic fetching of available plugins from a remote directory
- Hook System: Plugins can register hooks for extensibility
- Event System: EventEmitter-based communication between host and plugins
- Hot Reload: Support for unloading and reloading plugins
- Auto-Update: Periodic registry updates from the plugin directory
Installation
npm install
Usage
import { PluginHost } from './src/PluginHost.js';
const host = new PluginHost({
directoryUrl: 'http://your-plugin-directory/plugins',
pluginsDir: './plugins',
autoUpdate: true,
updateInterval: 300000 // 5 minutes
});
await host.initialize();
await host.loadPlugins();
Plugin Context API
Plugins receive a context object with the following API:
registerHook(hookName, callback)- Register a hookunregisterHook(hookName, callback)- Unregister a hookrunHook(hookName, ...args)- Execute a hookgetConfig(key)- Get plugin configurationlog(...args)- Log with plugin prefixon(event, listener)- Listen to host eventsemit(event, ...args)- Emit events
Events
initialized- Host initializedregistry-updated- Plugin registry updatedplugin-loaded- Plugin loadedplugin-unloaded- Plugin unloadedplugin-error- Plugin error occurredshutdown- Host shutting down
License
MIT
Description
Languages
JavaScript
100%