# Migrating configuration to a configuration node (or, programmatically instantiating a config node)

**URL:** <https://discourse.nodered.org/t/migrating-configuration-to-a-configuration-node-or-programmatically-instantiating-a-config-node/61154>\
**Category:** Developing Nodes\
**Created:** [12 April 2022 08:15 UTC](https://discourse.nodered.org/t/migrating-configuration-to-a-configuration-node-or-programmatically-instantiating-a-config-node/61154 "2022-04-12T08:15:34Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![BartButenaers](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bartbutenaers/32/10476_2.png) [@BartButenaers](https://discourse.nodered.org/u/BartButenaers)\
**Post date:** [3 August 2022 20:00 UTC](https://discourse.nodered.org/t/migrating-configuration-to-a-configuration-node-or-programmatically-instantiating-a-config-node/61154/4 "2022-08-03T20:00:27Z")

</div>

Hi @sverre,

I had overlooked your question, due to the large amount of posts that are created nowadays on Discourse. But it was a very good question!

Last night I was also wondering how I needed to do it, so I found your post. I have asked Paul to reopen this discussion, so I can share my solution. Perhaps you don't need it anymore, but then others might benefit from it ...

## The original node

In your original node you have a property with a default value:

```auto
<script type="text/javascript">
    RED.nodes.registerType('my-node',{
        defaults: {
            originalProperty: {value: "defaultValue"}
        },    
        ...
    });
</script>

```

That property is displayed on the node's config screen:

```auto
<script type="text/x-red" data-template-name="my-node">
   ...
   <div class="form-row">
        <label for="node-input-originalProperty">Original property</span></label>
        <input type="number" id="node-input-originalProperty">
   </div>
   ...
</script>

```

And the entered property value becomes available on the server side after a deploy:

```auto
 module.exports = function(RED) {
    var settings = RED.settings;

    function MyNode(config) {
        RED.nodes.createNode(this, config);
        this.originalProperty = config.originalProperty;
        ...
    }
    
    RED.nodes.registerType("my-node", MyNode);
}

```

So far so good. But as soon as lots of these nodes are added to a flow, people need to start copying the value of originalProperty to all those nodes to keep them in sync. Which is rather annoying...

## The updated node

So you want to introduce a config node, so users can enter their value in that config node (and re-use it in multiple nodes). But you need to migrate the original value into the config node, otherwise people will loose their original property values (because the original input field won't be visible anymore).

1. [Create](https://nodered.org/docs/creating-nodes/config-nodes) a config node (i.e. html and js file) which contains now the originalProperty:

2. Remove the original html input element _"node-input-originalProperty"_ because the original property shouldn't be visualized anymore on the node's config screen. Instead we will add a new input field, that will be used as a placeholder where Node-RED can show a dropdown with all available config nodes:

3. Since the original property values need to be migrated, make sure that those values are still being remembered by Node-Red by keeping the originalProperty under the cover:

4. As soon as the config screen of our original node is opened, a new config node needs to be instantiated (when there is no config node yet and there are original values to be migrated):

5. Update the server side (js file) to use the originalProperty from the config node. Or if there is no config node yet, use the originalProperty which is still available in the node (which will be the case if the user has not opened the node's config screen yet):

This way a new config node is automatically created when you open the node's config screen, where the original property value is displayed. And when a new node is dragged onto the flow, no new config node is created automatically: indeed the user perhaps want to re-use an existing config node...

Good luck!  
Bart

---

_[View the full topic](https://discourse.nodered.org/t/migrating-configuration-to-a-configuration-node-or-programmatically-instantiating-a-config-node/61154)._
