# I added a listener for the deployment event nodes:deploy, but it did not trigger

**URL:** <https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216>\
**Category:** General\
**Created:** [24 May 2024 03:40 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216 "2024-05-24T03:40:07Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 03:40 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/1 "2024-05-24T03:40:07Z")

</div>

I added a listener for the deployment event nodes:deploy, but it did not trigger. Other events, such as flows:started, can be triggered. There are also the following input events that can be triggered. hope to get help.  
I mainly want to save the current flowId when deploying for my business

```auto
module.exports = function (RED) {
  console.log("init: Can trigger");

  RED.events.on("nodes:deploy", function () {
    console.log("nodes:deploy: Here Can't trigger");
  });
  RED.events.on("flows:started", function () {
    console.log("flows:started: Can trigger");
  });

  function Device(config) {
    RED.nodes.createNode(this, config);
    this.on("input", function (msg) {
      console.log("Received:", msg.mydata);
      this.send(msg);
    });
  }
  RED.nodes.registerType("device", Device);
};

```

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [24 May 2024 05:36 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/2 "2024-05-24T05:36:17Z")

</div>

I only found the [RED.events.emit('deploy')](https://github.com/node-red/node-red/blob/da97c5d558f5485e038208b469b406815d63b9d4/packages/node_modules/%40node-red/editor-client/src/js/ui/deploy.js#L634) event - perhaps that's what you're looking for.

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 07:57 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/3 "2024-05-24T07:57:04Z")

</div>

This method doesn't seem to work either，I tried multiple ways of writing, but only one event triggered

```auto
module.exports = function (RED) {
  RED.events.on("flows:started", function () {
    // Only this event can trigger
    console.log("Trigger flows:started");
  });
  // Neither of these fire when I click the deploy button in the upper right corner
  RED.events.emit("deploy", function () {
    console.log("Trigger deploy");
  });
  // Neither of these fire when I click the deploy button in the upper right corner
  RED.events.emit("nodes:deploy", function () {
    console.log("Trigger nodes:deploy");
  });

  function Device(config) {
    RED.nodes.createNode(this, config);
    this.on("input", function (msg) {
      console.log("Received:", msg.mydata);
      this.send(msg);
    });
  }
  RED.nodes.registerType("device", Device);
};

```

---

<div class="post-metadata">

**Author:** ![gregorius](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gregorius/32/73816_2.png) [@gregorius](https://discourse.nodered.org/u/gregorius)\
**Post date:** [24 May 2024 08:08 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/4 "2024-05-24T08:08:43Z")

</div>

Your using emit instead of on - emit generates the event, on defines the trigger.

---

<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:** [24 May 2024 08:16 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/5 "2024-05-24T08:16:01Z")

</div>

> [@lyliang1216](#):
>
> `deploy`

The `deploy` event is an Editor event - not a Runtime event. It can only be used in the editor-side code.

`flows:started` is the main runtime event, albeit undocumented, that is available for this type of thing.

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 08:33 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/6 "2024-05-24T08:33:37Z")

</div>

Could you please tell me about the editor-side code you are talking about, where do you add content? Are you writing in the dragged node? I hope this event is a global event because I need to obtain the final flow information during deployment to associate it with the business. Or do you have any better suggestions?

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 08:36 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/7 "2024-05-24T08:36:34Z")

</div>

Well, I tried this, but it had no obvious effect. Is there any example that I can refer to?

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 08:43 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/8 "2024-05-24T08:43:54Z")

</div>

I think I should try using flows:started to listen to flow creation and update events.

---

<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:** [24 May 2024 08:56 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/9 "2024-05-24T08:56:39Z")

</div>

It would probably help if you described why you wanted to react to these events. Typically you do not need to. There may be other ways to look at the issue.

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 09:03 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/10 "2024-05-24T09:03:41Z")

</div>

Thanks.I jump to NodeRed from the front-end page with parameters. I need to set up the process for each device and associate the device ID with flowId. But I couldn't get the flowId, so I thought of listening to the deployment event. I also thought about getting it in the process and then sending it to the backend through http request, but this would be very troublesome, so I hope it can be done through a global event.

---

<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:** [24 May 2024 09:06 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/11 "2024-05-24T09:06:17Z")

</div>

The flow ID should be available once you have initialised a node instance. In your case, that will be in the `Device` function AFTER calling `createNode`. At that point, the `this` object should contain the data I think, if not, you can query it since `this` certainly contains the node id.

---

<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:** [24 May 2024 09:06 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/12 "2024-05-24T09:06:57Z")

</div>

If you want to know the flow id for a given node, then look at its `z` property:

```auto
function Device(config) {
    RED.nodes.createNode(this, config);
    const flowId = config.z
   
  }

```

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 09:12 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/13 "2024-05-24T09:12:16Z")

</div>

Yes, it can be done this way. Another question is when to associate the flow with my business equipment. I think the process will be completely completed and ready to use when I click deploy. This is the main problem. So I hoped to complete it by listening to the deployment event. In fact, I failed.

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 09:13 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/14 "2024-05-24T09:13:48Z")

</div>

Yes, there will be an ID after initialization, but I hope to do other operations after the flow editing is completed. What is the best time to process it? At present, I only think about monitoring deployment.

---

<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:** [24 May 2024 09:15 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/15 "2024-05-24T09:15:52Z")

</div>

I think this partly depends on whether you require Editor users to always do a full deploy. If you do, then the setup code of your node will always be triggered at that point.

On the other hand, if someone may change something that does not include your node and does a partial deploy, it won't trigger a setup in your node and in that case, you might indeed need to use an event listener.

---

<div class="post-metadata">

**Author:** ![lyliang1216](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/lyliang1216/32/91310_2.png) [@lyliang1216](https://discourse.nodered.org/u/lyliang1216)\
**Post date:** [24 May 2024 09:20 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/16 "2024-05-24T09:20:44Z")

</div>

In this case, I can only judge whether the user has completed editing by whether it is deployed, but this can only be monitored through deployment. Or save in real time during editing, in which case you also need to monitor the change event, but the side effect is that imperfect content will replace the original process. So it seems that the best way at present is to deal with it during deployment.

---

<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:** [24 May 2024 10:11 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/17 "2024-05-24T10:11:28Z")

</div>

I think I have to concur.

---

<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:** [22 August 2024 10:11 UTC](https://discourse.nodered.org/t/i-added-a-listener-for-the-deployment-event-nodes-deploy-but-it-did-not-trigger/88216/18 "2024-08-22T10:11:37Z")

</div>

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