# Messages sent via "On Start" only reliable on partial deploy but not during " nodered.service" start. Possible?

**URL:** <https://discourse.nodered.org/t/messages-sent-via-on-start-only-reliable-on-partial-deploy-but-not-during-nodered-service-start-possible/83989>\
**Category:** General\
**Tags:** function-node\
**Created:** [23 December 2023 16:41 UTC](https://discourse.nodered.org/t/messages-sent-via-on-start-only-reliable-on-partial-deploy-but-not-during-nodered-service-start-possible/83989 "2023-12-23T16:41:37Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [23 December 2023 18:07 UTC](https://discourse.nodered.org/t/messages-sent-via-on-start-only-reliable-on-partial-deploy-but-not-during-nodered-service-start-possible/83989/7 "2023-12-23T18:07:31Z")

</div>

> [@Mike-FUT](#):
>
> `node.done;`  
> return;

`node.done` is not needed (and it doesnt do anything without (brackets) anyhow)  
`return` is unnecessary if it is the last statement

So I did a test using:

```auto
let m = {};
m.payload = "Test Payload";
node.send(m);
node.error('deliberate node.error');

```

And sure enough i DO get a message in the console log.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/d/1/d1593042c8c73efdc4368ca7315465047e2aa9bf.png)

However the results are mixed, as I expected.

- FULL Deploy
  - The debug node does NOT receive a message

- Modify func node then do a NODE ONLY deploy - the msg is sent.
- recreate the function AFTER all other connected nodes, deploy (Full or Node only) and it DOES send

Proving that the `on start` occurs in order of node creation (the order the node is stored in the flow)

This, is not a reliable way to use "On Start" IMO. As i said before, to ensure all nodes are initialised and running, you should use an inject (as the inject wont fire untill the "Flows Started" message (i.e. all nodes are initialised)

Demo:

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/3/134e0a63024c8034aa1fa488bce97b9faea88513.png)

Demo flow (note how the function "I was added first" is at the top and the "I was added 2nd last" is 2nd from the bottom!

```auto
[
    {
        "id": "99ad09d05093ee4a",
        "type": "function",
        "z": "3642c7ee286f9c17",
        "name": "I was added first",
        "func": "\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "let m = {};\nm.payload = \"Test Payload 2\";\nnode.send(m);\nnode.error('deliberate node.error 2');\n",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 480,
        "wires": [
            [
                "44a542c2d5181115",
                "0484dedcdd96f7e7"
            ]
        ]
    },
    {
        "id": "f22eda38365a0e9b",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will work",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 630,
        "y": 260,
        "wires": []
    },
    {
        "id": "6e2f83184fe48a05",
        "type": "delay",
        "z": "3642c7ee286f9c17",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 480,
        "y": 380,
        "wires": [
            [
                "6a9a28c3aa062dc8"
            ]
        ]
    },
    {
        "id": "6a9a28c3aa062dc8",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will work after delay",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 670,
        "y": 380,
        "wires": []
    },
    {
        "id": "44a542c2d5181115",
        "type": "delay",
        "z": "3642c7ee286f9c17",
        "name": "",
        "pauseType": "delay",
        "timeout": "10",
        "timeoutUnits": "seconds",
        "rate": "1",
        "nbRateUnits": "1",
        "rateUnits": "second",
        "randomFirst": "1",
        "randomLast": "5",
        "randomUnits": "seconds",
        "drop": false,
        "allowrate": false,
        "outputs": 1,
        "x": 470,
        "y": 540,
        "wires": [
            [
                "f53dbbe2cc034447"
            ]
        ]
    },
    {
        "id": "0484dedcdd96f7e7",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will not work",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 640,
        "y": 480,
        "wires": []
    },
    {
        "id": "f53dbbe2cc034447",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will not work",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 640,
        "y": 540,
        "wires": []
    },
    {
        "id": "c2c7afc08e883d45",
        "type": "function",
        "z": "3642c7ee286f9c17",
        "name": "I was added 2nd last",
        "func": "\nreturn msg;",
        "outputs": 1,
        "timeout": 0,
        "noerr": 0,
        "initialize": "let m = {};\nm.payload = \"Test Payload\";\nnode.send(m);\nnode.error('deliberate node.error');\n",
        "finalize": "",
        "libs": [],
        "x": 300,
        "y": 320,
        "wires": [
            [
                "f22eda38365a0e9b",
                "6e2f83184fe48a05",
                "1dd9f3f48b9f1d7d"
            ]
        ]
    },
    {
        "id": "1dd9f3f48b9f1d7d",
        "type": "debug",
        "z": "3642c7ee286f9c17",
        "name": "I will NOT work (last node in flow)",
        "active": true,
        "tosidebar": true,
        "console": true,
        "tostatus": true,
        "complete": "payload",
        "targetType": "msg",
        "statusVal": "payload",
        "statusType": "auto",
        "x": 700,
        "y": 320,
        "wires": []
    }
]

```

---

_[View the full topic](https://discourse.nodered.org/t/messages-sent-via-on-start-only-reliable-on-partial-deploy-but-not-during-nodered-service-start-possible/83989)._
