Plugin System

Extend Novaxjs2 functionality with custom plugins:

Creating a Plugin

function myPlugin({addMethod,addRoute, addRoute, addMiddleware }, options) {
  // Add new methods
  addMethod('greet', function(name) {
    return `Hello ${name}!`;
  });
  
  // Add routes
  addRoute('get', '/plugin-route', (req, res) => {
    return 'This route was added by plugin';
  });
  
  // Add middleware
  addMiddleware((req, res, next) => {
    console.log('Plugin middleware');
    next();
  });
  
  // Store configuration
  setConfig('pluginConfig', options);
}

Using a Plugin

app.usePlugin(myPlugin, { setting: 'value' });

// Now you can use plugin methods
app.get('/', (req, res) => {
  return app.greet('World');
});

Plugin Configuration

// In your plugin:
function myPlugin({ setConfig, getConfig }, options) {
  // Store configuration
  setConfig('apiKey', options.apiKey);
  
  // Later retrieve it
  const apiKey = getConfig('apiKey');
}