On Startup node not receiving initialisation data

I've set a JSObject-generating node to generate "on startup" instead of "on message", as it was previously generating the same XML repeatedly and loading my Raspberry Pi (when the JSObject only needs generating once from XML, and setting to a global const). However, it seems to initialise before the injector nodes, never receives the initialisation data to trigger, and fails with "ReferenceError: msg is not defined".

2 questions:

  • Am I misunderstanding how "on startup" code works? How do I provide initialisation data for startup code?
  • Is the best way to set a global constant using a change node with global.var to msg.payload?


"On Startup" occurs on start of node-red. There is NO msg
To initialise something using a function node, put your code in the "On Message" part and trigger it using an inject set to fire at start up.

It is one way. Depends on requirements.

1 Like

Thank you for confirming my suspicions - I have implemented it exactly as you said, and it works.

I was using a change node, but then switched to the one-liner global.set ("look_up_table", msg.payload); at the end of the function. Tested as working.

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