# How plugins can communicate with each other?

• If you, say, require a NodeBB plugin, it will fail because it looks for module.parent to require things.

So, how can I build a plugin that can share functionality with other plugins and then use that plugin's functionality in other plugins?

• Although not ideal you can require a plugin from node_modules. It might be better to put the plugin you depend on in your plugins package.json though so it is installed when your plugin is installed. Although I'm not sure if nested plugins like that are handled properly by the hook system.

• @baris even if I rewire a plugin from node modules, it still looks for the NodeBB module.parent ime.

• Yeah all the plugins assume they are required from src/plugins.js from core so that is kind of limiting. https://github.com/NodeBB/NodeBB/blob/master/src/plugins.js#L187

• Add the other plugin as a peer dependency, fire custom hooks. That's how I did it.

Also another way I did was to use the socket namespace of the plugin in question. Because coincidentally I needed to execute those.

• @pitaj Something to note is that if the plugin has already been required, subsequent requires will still have module.parent pointing to the first module that required it.

So... when NodeBB starts and it requires plugin-foobar, its module.parent is plugins.js

Later, if plugin-barbaz requires plugin-foobar, its module.parent stays as plugins.js.

So if you only require the module after NodeBB is done with it (e.g. defer requiring until it is actually required), you might be ok.

8

2

5