# Stuck using config node multiple times

**URL:** https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477
**Category:** Developing Nodes
**Created:** [11 January 2022 15:53 UTC](https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477 "2022-01-11T15:53:45Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![danube](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danube/32/34348_2.png) [@danube](https://discourse.nodered.org/u/danube)
#### Post date: [11 January 2022 15:53 UTC](https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477/1 "2022-01-11T15:53:45Z")

</div>

Hey there! I'm stuck understanding one simple mechanism. Please enlighten me.

I use a config node and as far as I learned from the docs, I get the content with RED.nodes.getNode. So I do:

Let me describe the situation with the option "bool". In JS, I do:

```auto
module.exports = function(RED) {
    function configNode(config) {
        RED.nodes.createNode(this,config)
		this.config = config
	}
    RED.nodes.registerType("mytemplate-config",configNode);
	
	function workingNode(config) {
		RED.nodes.createNode(this,config)
		let parms = RED.nodes.getNode(config.config)
		...
	RED.nodes.registerType("mytemplate",workingNode);
}
...

```

Which gives me the console output:

```auto
configNode {
  id: 'f476dc6e65b0a93d',
  type: 'mytemplate-config',
  z: undefined,
  g: undefined,
  _closeCallbacks: [],
  _inputCallback: null,
  _inputCallbacks: null,
  name: 'myparms',
  wires: [],
  _wireCount: 0,
  send: [Function: NOOP_SEND],
  config: {
    id: 'f476dc6e65b0a93d',
    type: 'mytemplate-config',
    name: 'myparms',
    valueType: 'bool',
    value: 'true',
    _users: ['01a83f7c216f97b8', 'd2ef1c167664e574']
  }
}

```

One parameter field config.value is a typedInput allowing ["bool","num","str"]. I learned that "bool" and "num" are also stored as strings and I have to convert it first. Now in JS I do:

```auto
...
if (parms.config.valueType === "bool") {
	parms.config.value = parms.config.value === "true"
}
...

```

Resulting in:

```auto
valueType: 'bool',
value: true,

```

Great. But when calling the node a second time, it fails. If I add a console.log before and after conversion, I see that the second node, before conversion, holds the value from the conversion of the first node.

```auto
BEFORE CONVERSION
configNode {
  ...
  config: {
    ...
    valueType: 'bool',
    value: 'true',
    ...
  }
}
AFTER CONVERSION
configNode {
  ...
  config: {
    ...
    valueType: 'bool',
    value: true,
    ...
  }
}
BEFORE CONVERSION
configNode {
  ...
  config: {
    ...
    valueType: 'bool',
    value: true,
    ...
  }
}
AFTER CONVERSION
configNode {
  ...
  config: {
    ...
    valueType: 'bool',
    value: false,
    ...
  }
}

```

Find the complete code here: [GitHub - danube/template](https://github.com/danube/template)

Doh... kinda hard to explain, hope you got it. Now may you guide me to the right path please... Regards! Thomas

---

<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: [11 January 2022 16:55 UTC](https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477/2 "2022-01-11T16:55:05Z")

</div>

Hi Thomas, you could take the easy way out and change your test to:

```auto
...
if (parms.config.valueType === "bool") {
	parms.config.value = ( parms.config.value === "true" || parms.config.value === true )
}
...

```

Doubtless there are more elegant ways but that seems simple, and direct if a little brutal. 🙂

---

<div class="post-metadata">

### Author: ![danube](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/danube/32/34348_2.png) [@danube](https://discourse.nodered.org/u/danube)
#### Post date: [12 January 2022 06:27 UTC](https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477/3 "2022-01-12T06:27:55Z")

</div>

Hi and thanks for taking time!

There is just one major thing I don't understand. I call the same node twice with the same configuration node(!). In the code I create a copy of the config with

```auto
let parms = RED.nodes.getNode(config.config)

```

and then do the manipulation:

```auto
parms.config.value = parms.config.value === "true"

```

This works for the first call of the node, where the type is being converted from STRING 'true' to BOOL true. But on the second call, I see a BOOL before conversion. Remember: Same code, same config node! For some weird reason it seems to me that the second node call holds the value converted by the first call.

---

<div class="post-metadata">

### Author: ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)
#### Post date: [12 January 2022 07:31 UTC](https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477/4 "2022-01-12T07:31:49Z")

</div>

If you modify `params` then you are modifying the config node and any other users of that node will see the change.

It would be cleaner to to any property validation/cleanup in the config node itself so all consumers of it will benefit and don't need to do it themselves.

---

<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: [13 March 2022 07:32 UTC](https://discourse.nodered.org/t/stuck-using-config-node-multiple-times/56477/5 "2022-03-13T07:32:38Z")

</div>

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