How to design a plugin architecture in Node.js?
I have a Node.js application and I want users to be able to develop custom plugins. I have multiple ideas and I am unsure how good they are. I need some tips from more experienced developers. My first idea is the following: Write an npm package that defines a plugin interface While my application is running: run npm install as child_process Dynamically import the plugin via import(). Communication is direct, the application just calls the interface functions, the plugin runs in the same process Second idea: Write an npm package that defines a plugin interface, the interface listens to messages from a parent process While my application is running: Run git clone && cd && npm install && npm start as child_processes. Communication works through child_process.send(msg). In both situations users will be able to add plugins to my software just by providing my software either a link (to the github repository) or the name of the npm package. This makes it possible to install plugins from anyone. I am not sure with my ideas, to be honest I don't feel happy with both solutions. The first seems very insecure, because plugin and application share the same process. Or is this common for plugins? The second one seems to be more secure, because the code is running in a child process, but this results in one extra node_modules folder per plugin. Is it even possible to build a secure and lightweight plugin architecture?

I have a Node.js application and I want users to be able to develop custom plugins. I have multiple ideas and I am unsure how good they are. I need some tips from more experienced developers.
My first idea is the following:
- Write an npm package that defines a plugin interface
- While my application is running: run
npm install
aschild_process
- Dynamically import the plugin via
import()
. Communication is direct, the application just calls the interface functions, the plugin runs in the same process
Second idea:
Write an npm package that defines a plugin interface, the interface listens to messages from a parent process
While my application is running: Run
git clone
as&& cd && npm install && npm start child_processes
.Communication works through
child_process.send(msg)
.
In both situations users will be able to add plugins to my software just by providing my software either a link (to the github repository) or the name of the npm package. This makes it possible to install plugins from anyone.
I am not sure with my ideas, to be honest I don't feel happy with both solutions.
The first seems very insecure, because plugin and application share the same process. Or is this common for plugins?
The second one seems to be more secure, because the code is running in a child process, but this results in one extra node_modules
folder per plugin.
Is it even possible to build a secure and lightweight plugin architecture?