Determine the number of wires connecting to an output port

Hi all,

So, a silly question, I have a node with one input port, and two output ports. The first output port is used to return the results of operations, whilst the second is used to emit debugging information.

I'd like to only emit debug messages if and only if there is something actually connected to that port.

Internally, I'll probably be leaning heavily on NodeJS's EventEmitter class, and for that, it has a listenerCount method which tells me how many "listeners" have been connected to a given signal.

It'd be really nice if I could, in my node, say:

node.on("input", (msg, send, done) => {
    let myobj = new MyObject();
    if (node.getNumberOfConnectionsToOutputPort(1) > 0) {
        myobj.on('debug', (debugmsg) => {
            /* emit a debug message */
            send([[], [debugmsg]]);
    return myobj.doSomethingWith(msg, send).then(done).catch(done);

What I do not know, is what getNumberOfConnectionsToOutputPort is actually called, or even if it exists.

Is there such a function? If so, where can I read up about it?

The node.wires property is an array of arrays that corresponds to the connections to the outputs , so should be what you want.

Many thanks… I just tried adding the following code to my node's input handler.

node.log('Wire connections: \n' + JSON.stringify(node.wires, null, 4));

Got this in the logs…

15 Nov 22:23:46 - [info] [widesky-cet-read-history:c2555ef3.abae88] Wire connections: 

Looks like that has what I'm after. Many thanks. I spent quite some time looking around for the API specs on the node object but kept going around in circles. This helps a lot.

1 Like

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