2

For a NodeJS server application i need to implement dynamic extendability with a plugin-like system. Goal is to be able, to hook in extended calculations by simple plugins, which select when and how to run by events they register for at the main app.

  • Within a folder "./plugins" each plugin should live in a subfolder.
  • The plugins should be loaded by the application automatically at startup.
  • No change at the application code is allowed for introducing a new plugin.
  • Plugins should be able to register for events in main application.
  • Communication between the plugins should be possible in some way

Is there any ready to use framwork for this requirement or are there any rock solid architecture approaches for this?

Regards

Boxson

1 Answer 1

1

Found a solution after some try and error:

  • Read the plugins directory (fs) and scan for subfolders
  • Check if there is a manifest.json file inside the subfolder
  • if manifest.json exists, read this file and parse content as JSON object
  • push the JSON object into an array (plugin list array)
  • iterate over the plugin list array and require the plugin main.js file
  • plugins register for events of the plugin manager object (made accessable via global.pluginmanager = pluginmanager

With appropriate error handling this seems to work solid.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.