Skip to content

plugin() & getPlugins()

app.plugin(fn, [options])
NameTypeDescription
fnFunctionPlugin function with signature (app, options) => void.
optionsObjectOptional configuration passed to the plugin.

Returns: app (for chaining).

function greetPlugin(app) {
app.addRoute("/greet", {
get: (req, res) => res.json({ hello: "world" }),
});
}
app.plugin(greetPlugin);
// With options
app.plugin(corsPlugin, { origin: "https://mysite.com" });
// Chaining
app
.plugin(authPlugin)
.plugin(loggingPlugin)
.start(3000);

Kaelum uses fn.name or fn.pluginName for dedup:

app.plugin(authPlugin);
app.plugin(authPlugin); // ❌ throws — already registered

Anonymous plugins (arrow functions without names) can be registered multiple times.


app.getPlugins()

Returns: string[] — list of registered plugin names.

app.plugin(authPlugin);
app.plugin(loggingPlugin);
console.log(app.getPlugins());
// ["authPlugin", "loggingPlugin"]