# How to emit events?

**URL:** https://discourse.nodered.org/t/how-to-emit-events/49839
**Category:** Developing Nodes
**Created:** [17 August 2021 12:18 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839 "2021-08-17T12:18:40Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Daft11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daft11/32/46631_2.png) [@Daft11](https://discourse.nodered.org/u/Daft11)
#### Post date: [17 August 2021 12:18 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/1 "2021-08-17T12:18:40Z")

</div>

Hello!  
I'm creating custom node and having a hard time understanding how to execute/trigger/emit custom event (with listener in js part) from editor (html part). Is that even possible?

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [17 August 2021 12:41 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/2 "2021-08-17T12:41:15Z")

</div>

The editor code runs in the browser. The Node-RED event emitter lives in the runtime as it is a node.js feature.

However, you can easily create a simple event handler in the browser. BUT it really depends what you are actually trying to achieve. Especially bearing in mind that some nodes isolate the scripts in the editor by wrapping them in an IIFE.

You can also find an example browser-based event handler in uibuilder's front-end library. The following is taken from Stack Overflow:

```auto
var class_test = function() {
   this.dispatcher = $({})
}

Class_test.prototype = {
   some_property: null,

    doSomething: function(msg) {
            this.some_property = msg
            this.dispatcher.trigger("somethingHappened")
    }
};

var test = new Class_test()

test.dispatcher.on('somethingHappened', function() {
    alert("Event")
})

test.doSomething('Example')

```

---

<div class="post-metadata">

### Author: ![Daft11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daft11/32/46631_2.png) [@Daft11](https://discourse.nodered.org/u/Daft11)
#### Post date: [17 August 2021 12:51 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/3 "2021-08-17T12:51:37Z")

</div>

Thank you for reply!  
In truth, i need to perform HTTP request while editing node properties. Maybe you could recommend better approach?

---

<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: [17 August 2021 13:04 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/4 "2021-08-17T13:04:28Z")

</div>

Hi @Daft11

this Stack Overflow answer outlines how you can do it: [javascript - Send data on configuration - Stack Overflow](https://stackoverflow.com/questions/41567175/send-data-on-configuration/41567832#41567832)

Essentially, you create an admin HTTP endpoint in your node's .js file that you can call from the node's .html file. They key things are to setup the paths properly on both sides.

Make sure you pick a path that is named for your node so it is unlikely to clash with any other admin end point.

---

<div class="post-metadata">

### Author: ![TotallyInformation](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/totallyinformation/32/31_2.png) [@TotallyInformation](https://discourse.nodered.org/u/TotallyInformation)
#### Post date: [17 August 2021 13:30 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/5 "2021-08-17T13:30:24Z")

</div>

In addition to Nicks reply, you will find examples in any number of nodes and it is worth looking at the source code for those nodes as this is a great way to learn.

node-red-contrib-uibuilder contains a number of admin API endpoints for example.

There is one that looks up all of the url settings for all of the deployed uibuilder node instances to ensure that you cannot accidentally reuse the same name. Other ones allow the editor config panel get access to folders and files on the Node-RED server's uibRoot folder. Others allow management of npm packages.

---

<div class="post-metadata">

### Author: ![Daft11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/daft11/32/46631_2.png) [@Daft11](https://discourse.nodered.org/u/Daft11)
#### Post date: [17 August 2021 16:34 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/6 "2021-08-17T16:34:52Z")

</div>

Extremely grateful for the answer!

---

<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: [31 August 2021 16:35 UTC](https://discourse.nodered.org/t/how-to-emit-events/49839/7 "2021-08-31T16:35:36Z")

</div>

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