Skip to main content

Plugins

Plugins are functions that run when the server boots and is an easy way to extend your application.

Generate a plugin with the Kult CLI

Run the kult command and follow the prompts to create a new local plugin

bash
kult

Once a plugin has been created the directory will have the following folder structure:

  • src/plugins
    • logger
      • index.ts

Local plugins

A local plugin will be loaded automatically.

src/plugins/logger/index.ts
import { Application, KultPlugin, PluginBase } from '@kult/core';

@KultPlugin('Logger')
export default class Logger extends PluginBase {
constructor(app: Application) {
super(app)
}
}

External plugins

External plugin packages need to be added to the plugins array in src/app/config/plugins.ts

src/app/config/plugins.ts
import PluginTemplate from '@kult/plugin-template';

export default {
plugins: [PluginTemplate],
};

Once the plugin gets instantiated a reference to the Application object will passed to the constructor:

constructor(app: Application) {
super(app);
}

Example

Have a look at the plugin template repo