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.

Hey,
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.

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 ?

I would also consider a "deploy completed" event/hook of some sort to be useful.

Particularly with embedded apps with lots of custom content having some way to react to a deploy and perform some operations that may be outside of the scope of the client (e.g, running some sort of test code, or pulling information out about current flow context after each deploy in my case).

I did some digging into the node-red source code and found that there actually is a deploy completed event fired on the client side, while on the server the best way to currently sniff out an event is to inject in some express middleware to tamper with post requests that hit /flows like this:

const tamper = require('tamper')

    app.use(tamper((req, res) => {
      if (req.method !== 'POST' && req.url !== '/flows') {
        return
      }

      return body => {
        if (JSON.parse(body).rev) {
          console.log('this will be after a deploy')
          // execute your custom functionality here
        }

        return body
      }
    }))

If you're open to the addition of a server side event for this I'd be happy to open a pull request adding one in.