# Best way to send a message only when Node-RED has started and running

**URL:** https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958
**Category:** General
**Created:** [1 March 2023 17:45 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958 "2023-03-01T17:45:23Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [1 March 2023 17:45 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/1 "2023-03-01T17:45:23Z")

</div>

What is the best way to detect Node-RED starting, running so I can start a connection to OPC-UA I/O?

Thanks,

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [1 March 2023 17:49 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/2 "2023-03-01T17:49:40Z")

</div>

You can use an `inject` node with the **once option** , which will send a single message after 0.1s (configurable).

---

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [1 March 2023 18:01 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/3 "2023-03-01T18:01:26Z")

</div>

Sure, Is it that simple?

I guess what I was asking is this the means for a "First Scan" ? Maybe this is it.

I got looking at "Function" and the On Start script. Not sure the purpose of this. The context isn't clear.

Thanks.

---

<div class="post-metadata">

### Author: ![GogoVega](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gogovega/32/71313_2.png) [@GogoVega](https://discourse.nodered.org/u/GogoVega)
#### Post date: [1 March 2023 18:19 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/4 "2023-03-01T18:19:50Z")

</div>

You can also use the "On Start" part in which you add this to send a message at startup:

```js
node.send({ payload: "Started" });

```

No `inject` node needed for this option.

---

<div class="post-metadata">

### Author: ![omrid](https://avatars.discourse-cdn.com/v4/letter/o/77aa72/32.png) [@omrid](https://discourse.nodered.org/u/omrid)
#### Post date: [1 March 2023 18:34 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/5 "2023-03-01T18:34:39Z")

</div>

As far as I know (and would ask to be corrected in case I'm wrong), there is a risk that the sender node sends the on-start message to a node which has not been initialized yet and cannot receive the message.  
Since the node initialization sequence goes tab by tab, left to right, I would suggest to place the initiating node as the last-created node on the last (rightmost) tab, and use a link out to send the on-start message to its destination.

---

<div class="post-metadata">

### Author: ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)
#### Post date: [1 March 2023 19:13 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/6 "2023-03-01T19:13:00Z")

</div>

Or simply wait ten seconds or so after startup to send your message. That's how mine is setup and seems to be reliable.

---

<div class="post-metadata">

### Author: ![tree-frog](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tree-frog/32/89303_2.png) [@tree-frog](https://discourse.nodered.org/u/tree-frog)
#### Post date: [9 March 2023 23:59 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/7 "2023-03-09T23:59:25Z")

</div>

node.send({ payload: "Started" });

This is what I was looking to do. Thanks!

---

<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: [9 April 2023 00:58 UTC](https://discourse.nodered.org/t/best-way-to-send-a-message-only-when-node-red-has-started-and-running/75958/8 "2023-04-09T00:58:12Z")

</div>

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