# Allow to get comms connections by Module APIs to send notifications to client

**URL:** <https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530>\
**Category:** Feature Requests\
**Created:** [12 January 2022 14:15 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530 "2022-01-12T14:15:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![bubus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bubus/32/44356_2.png) [@bubus](https://discourse.nodered.org/u/bubus)\
**Post date:** [12 January 2022 14:15 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/1 "2022-01-12T14:15:04Z")

</div>

Hello,

Is it possible to add getter for connections inside _@node-red/runtime/lib/api/comms.js_ or is there some reason why it is not implemented?

The getter is as simple as `getConnections: function() { return connections; },` inside module.exports.

With that feature now it is possible to send notifications to client while using Node-RED embeeded in express app.

```auto
const comms = RED.runtime.comms;
let connections = comms.getConnections();
connections.forEach(connection => {
        connection.send("notification/test123", {
            text: "Some error happened on server side",
            type: "error",
            timeout: 2000
        })
    })

```

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/b/6b34bc31da87095707613d602b23d2a07731107a.png)

As i searched through Node-RED code I did not find any way to do it without this modification, or maybe it is somehow possible?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 January 2022 14:22 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/2 "2022-01-12T14:22:20Z")

</div>

If you want to emit an event to all connected editors you would do:

```auto
RED.events.emit("runtime-event", {
   id: "test123",
   payload: {
      text: "Some error happened on server side",
      type: "error",
      timeout: 2000
   }     
})

```

What's your scenario for wanting to do this? Node's shouldn't generally be sending the editor events like this.

---

<div class="post-metadata">

**Author:** ![bubus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bubus/32/44356_2.png) [@bubus](https://discourse.nodered.org/u/bubus)\
**Post date:** [12 January 2022 14:37 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/3 "2022-01-12T14:37:42Z")

</div>

Ok, thank you!  
I did not know that it is possible this way.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 January 2022 14:52 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/4 "2022-01-12T14:52:12Z")

</div>

@bubus But I would like to know what your scenario is. If a node encounters an error it should be using the existing error logging mechanism that would allow the flow to handle the event. You cannot assume anyone has an editor open at that point in time.

---

<div class="post-metadata">

**Author:** ![bubus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bubus/32/44356_2.png) [@bubus](https://discourse.nodered.org/u/bubus)\
**Post date:** [12 January 2022 16:33 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/5 "2022-01-12T16:33:20Z")

</div>

It is not only for errors. In parallel with RED.log I want to inform user also by notification at some points that are triggered by RED.hooks, express middleware etc. -\> for example when there is limit of used nodes on particular tenant and it is exceeded.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [12 January 2022 16:58 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/6 "2022-01-12T16:58:36Z")

</div>

If they are more about 'edit time' notifications, then that is an appropriate use.

---

<div class="post-metadata">

**Author:** ![bubus](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bubus/32/44356_2.png) [@bubus](https://discourse.nodered.org/u/bubus)\
**Post date:** [26 January 2022 19:00 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/7 "2022-01-26T19:00:11Z")

</div>

Hello, just one more question is it possible to emit event only to specific user? Or to emit custom event to all users and catch it on client side?

I tried to catch custom event on client side with:

```auto
RED.comms.subscribe("customEvent/#")
RED.events.on("customEvent")

```

But could not manage to make it work. However if something like this is possible then in event handler (client side) I can do something like that:

```auto
if(RED.settings.get("user")?.username===msg.payload.username){
RED.notify(msg.payload.msg,{type:msg.payload.type}
}

```

---

<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:** [27 March 2022 19:00 UTC](https://discourse.nodered.org/t/allow-to-get-comms-connections-by-module-apis-to-send-notifications-to-client/56530/8 "2022-03-27T19:00:26Z")

</div>

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