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

**URL:** <https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926>\
**Category:** General\
**Tags:** function-node\
**Created:** [3 June 2023 15:42 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926 "2023-06-03T15:42:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Moosbueffel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moosbueffel/32/36732_2.png) [@Moosbueffel](https://discourse.nodered.org/u/Moosbueffel)\
**Post date:** [3 June 2023 15:42 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926/1 "2023-06-03T15:42:15Z")

</div>

I have a flow-variable like this:

```auto
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,....

Thanks

---

<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:** [3 June 2023 16:04 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926/2 "2023-06-03T16:04:40Z")

</div>

> [@Moosbueffel](#):
>
> How can I protect the variables: "name, topic and power"?

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.

> [@Moosbueffel](#):
>
> the identifier "const" is not usable in JS.

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.

> [@Moosbueffel](#):
>
> 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,....

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.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [3 June 2023 16:20 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926/3 "2023-06-03T16:20:32Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Moosbueffel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moosbueffel/32/36732_2.png) [@Moosbueffel](https://discourse.nodered.org/u/Moosbueffel)\
**Post date:** [3 June 2023 16:38 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926/4 "2023-06-03T16:38:38Z")

</div>

> [@TotallyInformation](#):
>
> 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, 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

---

<div class="post-metadata">

**Author:** ![Moosbueffel](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/moosbueffel/32/36732_2.png) [@Moosbueffel](https://discourse.nodered.org/u/Moosbueffel)\
**Post date:** [3 June 2023 16:39 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926/5 "2023-06-03T16:39:23Z")

</div>

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

---

<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:** [17 June 2023 16:39 UTC](https://discourse.nodered.org/t/howto-protect-a-object-property-how-to-find-who-write-to-this-property/78926/6 "2023-06-17T16:39:35Z")

</div>

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