# How can I share my custom event emitter between the node and the runtime side

**URL:** <https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709>\
**Category:** Developing Nodes\
**Created:** [3 April 2022 09:25 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709 "2022-04-03T09:25:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![steinmetz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinmetz/32/57992_2.png) [@steinmetz](https://discourse.nodered.org/u/steinmetz)\
**Post date:** [3 April 2022 09:25 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/1 "2022-04-03T09:25:17Z")

</div>

Continuing the discussion from [Event emitter for function object in separate module](https://discourse.nodered.org/t/event-emitter-for-function-object-in-separate-module/48850/2):

I need to watch all nodes (HTML elements) of a flow and then send them to a database. My idea is to create a custom event emitter and then listen to the event `deploy`, get all nodes via `createCompleteNodeSet` and then call my custom event handler to send it to a specific node.

So far, I did not manage to use my custom event emitter inside the node and on the client side. Is it even possible to do so? Do you have any examples of it?

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)\
**Post date:** [3 April 2022 11:14 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/2 "2022-04-03T11:14:03Z")

</div>

By "client side", I assume you mean the Editor? AFAIK, there are only two ways to communicate between the Editor and the runtime elements of a custom node.

1. An API web endpoint created by your runtime, called by a function in the node's Editor code.
2. Via the defined variables in your node.

As the two environments are entirely separate contexts, Event Emitters won't be enough.

---

<div class="post-metadata">

**Author:** ![steinmetz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinmetz/32/57992_2.png) [@steinmetz](https://discourse.nodered.org/u/steinmetz)\
**Post date:** [3 April 2022 11:51 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/3 "2022-04-03T11:51:21Z")

</div>

Thank you for your answer!

Yes, I mean the Editor.  
I need to send data from the Editor (HTML file of the node) to the runtime part.  
I will try your two suggestions!

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [3 April 2022 12:55 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/4 "2022-04-03T12:55:21Z")

</div>

Describe your full use case.

An important thing to remember, the runtime will continue to run without any editor sessions connected

---

<div class="post-metadata">

**Author:** ![steinmetz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinmetz/32/57992_2.png) [@steinmetz](https://discourse.nodered.org/u/steinmetz)\
**Post date:** [3 April 2022 13:41 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/5 "2022-04-03T13:41:09Z")

</div>

I've defined a set of nodes that users can use to model their systems. When the user clicks on Deploy, I want to get all used nodes and save them in a database.  
As far as I know, the only way to get all nodes of a flow is on the Editor side (right?).  
Therefore, I am listening to the deploy event and get all nodes like this:

```auto
RED.events.on('deploy', function () {

      let allNodes = RED.nodes.createCompleteNodeSet();

}

```

After I have all nodes, I will format them into the specific query language of the database (SQLite, MongoDB...) and then send it to another node (third party node) that will save it in the database.

My understanding is that I have to get all nodes on the Editor side and send them to the runtime which will then forward it to the database node. As suggested by @TotallyInformation, I think I will do it via API web. What do you think?  
I also found this doc that says something related to it: [Runtime Editor Comms protocol · node-red/node-red Wiki · GitHub](https://github.com/node-red/node-red/wiki/Runtime-Editor-Comms-protocol#message-structure)

But I would be happy to hear your thoughts on that too!  
Thank you!

---

<div class="post-metadata">

**Author:** ![hardillb](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/hardillb/32/12373_2.png) [@hardillb](https://discourse.nodered.org/u/hardillb)\
**Post date:** [3 April 2022 14:12 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/6 "2022-04-03T14:12:46Z")

</div>

So basically you are not actually using the Node-RED runtime at all, you just want to use the editor to model your environment.

In that case I think you are approaching the problem in the wrong way. And I suggest 2 better options

1. Write a custom storage plugin, this way every time the flow is deployed you will be passed the whole flow and you can choose to store it where and how ever you want. [Storage API : Node-RED](https://nodered.org/docs/api/storage/)

2. Don't use the Node-RED backend at all. There is a skeleton project that just provides enough API to serve the editor that you could adapt to do what you want, you would then edit the API endpoint that Deploy posts the flow to and again do as you please. [GitHub - node-red/node-red-learn](https://github.com/node-red/node-red-learn)

And no, the Runtime Editor Comms protocol is not what you are looking for.

---

<div class="post-metadata">

**Author:** ![steinmetz](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steinmetz/32/57992_2.png) [@steinmetz](https://discourse.nodered.org/u/steinmetz)\
**Post date:** [3 April 2022 14:44 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/7 "2022-04-03T14:44:37Z")

</div>

I got your point. I will learn more about the Storage API, probably this will solve my problem, as you said.

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [2 June 2022 14:44 UTC](https://discourse.nodered.org/t/how-can-i-share-my-custom-event-emitter-between-the-node-and-the-runtime-side/60709/8 "2022-06-02T14:44:42Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
