Continuing the discussion from Event emitter for function object in separate module:
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.
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.
- An API web endpoint created by your runtime, called by a function in the node's Editor code.
- Via the defined variables in your node.
As the two environments are entirely separate contexts, Event Emitters won't be enough.
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!
Describe your full use case.
An important thing to remember, the runtime will continue to run without any editor sessions connected
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:
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
But I would be happy to hear your thoughts on that too!
Thank you!
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
-
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
-
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
And no, the Runtime Editor Comms protocol is not what you are looking for.
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!
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.