Where can I find up to date info about RED.events?

This page starts with a big deprecation warning : https://github.com/node-red/node-red/wiki/API-Reference#server-library-register

The API docs aren't really helpful in my case: https://nodered.org/docs/api/modules/v/0.20.0/@node-red_runtime_events.html

I don't think we do have an up to date list of events that isn't in my head or findable in the code by looking for RED.events.emit.

Is there something specific you are interested in?

Trying to figure out how to properly remove event listeners in a private node I'm working on...
Basically, every time I deploy, all my listeners are duplicated.
ES6 arrow functions are fun until you try removing listeners :wink:

Ah right - RED.events is an instance of EventEmitter - https://nodejs.org/docs/latest-v10.x/api/events.html

The only way to remove an event listener is by holding a reference to the function to pass it to RED.events.removeListener(...).

1 Like

Cool, thanks Nick.

this topic seems to match 100% so i don't open another.

i was searching for a list of available RED.events because i wanted to do the following:
im tying to hook into the deploy mechanism.

Im stuck because the only event i could figure out was RED.events.emit("deploy");
And this is somehow to early for me.
I got a node which is writing some flow context which i want to post-process after a deploy.

  • Node has changes
  • pressing deploy button
  • (pre-deploy hook) -> deleting flow-context via api call
  • executing core:deploy-flows
  • (post-deploy hook) -> adding additional nodes based on the flow changes and flow-context -> posting new flow via api, making also a merge.

if i use the "deploy" event, the node has not written the flow-context yet.

i also tried it with a workspace:dirty event.
because when deploy is almost ready it sets the isDirty marker to false.

any help is appreciated!

There are no such hooks available today.

Can you expand a bit more on what you are trying to do? If you want to delete flow context why not do it in the 'close' event handler of the node?

What's the scenario for adding nodes dynamically as part of the Deploy process? I assume this is a very custom version of Node-RED you are trying to create as we wouldn't expect 'normal' nodes to be doing that sort of thing.

That's rights. It's going to be a custom version of NodeRed and you are able to model a flow which contains mainly conversion logic and use it with a communication configuration. One of the nodes is a flow configuration node, which describes the communication of each graph and saves it inside the context. This way we are much more flexible because the communication nodes like http, mqtt will be deleted and reinserted via configuration on deploy.

The only way that worked for me was using the RED.events.emit("deploy") Event with a delay of 500ms. Thats not really reliable, but at the moment the best way to go. I was hoping for an event after the backend has refreshed.

The deletion of the flow-context is not a problem. Im doing it with a own deploy button and calling afterwards the action "deploy-flows", only the shortcut CTRL+D is giving me some problems here, but i havn't searched yet the code for a solution.
The main problem is that the deploy hook is beeing called before everything is really saved and merged and reloaded in the backend. So that my merge in the deploy hook get some timing problems if i do not sleep for 500ms before i merge my additional nodes.

let me sum up:
there is a deploy event in the deploy.js which i would like to use, but due to asynchronous operations before it's not very useful for my situation is think. i have to wait until the flow in deploy.js is "really" deployed and the reload api call is through.

Make this sense? Waiting for the calls to finish and then send the deploy event? Alternatively introducing a deploy_completed event ?