HowTo protect a object property? How to find who write to this property?

I have a flow-variable like this:

const consumers = [
        "name" : "Hzg Bad_A",            // Consumer name
        "topic": "cmnd/eg/bad/th01/power",   // MQTT topic; zum steuern "cmnd/" voransetzen
        "power": 300,                   // Power requirement in W
        "active": false,                // true == consumer active/switched on; false == consumer switched off
        "working": true,                // true==consumes power; false==does not consume power
        "restartTimer": 0,              // Delay time for restart, if working==false
        "autoControl": true,            // true==mode automatic; false==mode manual
        "timer": 0,                     // Switch-off delay, if autoControl==false
  1. How can I protect the variables: "name, topic and power"? the identifier "const" is not usable in JS.
  2. Currently somewhere in my code overwrite the name. How can I debug/find the codeline/node?
    Is there something similar to traditional languages like Breakpoint on writing to this variable,
    searching for all codeLines using this variable,....


You cannot. There are deep ways in JavaScript itself to do so but none of them are exposed in the handlers for context variables.

You could, of course, build a custom node and do it that way if you really wanted to.

Not sure what you mean? const is an instruction in JavaScript certainly. However, when working with objects in JavaScript, const refers to the whole object and not to its properties. To protect individual properties, you need to create a custom object.

Yes, Node-RED is a node.js app and you can start a node.js app in debug mode and monitor things in your browser's dev tools. You can even use something like VScode to do the monitoring. Plenty of explanations in previous threads in the forum.

  1. Export your flow (set it to export formatted) and copy it into a text editor
  2. in the text editor do a find using 'flow'.

For each place you find it you can determine it this was a set of a flow variable. You can get the node's ID and use that to do a fine in the NR editor to locate the node.

It will take some work but you should be able to find where you are updating the flow variable.

Yes, you understand me right. I meant the propery of an object.
The posts for debug a node.js app I found. I just have to try. Seems not so easy to setup, but I'll try.

Thanks for your answer

Thanks @zenofmud I good idea, worth to try :).

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