# Modify the node instance definition from the runtime?

**URL:** https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274
**Category:** Developing Nodes
**Created:** [19 February 2021 03:15 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274 "2021-02-19T03:15:24Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![zachowj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zachowj/32/37522_2.png) [@zachowj](https://discourse.nodered.org/u/zachowj)
#### Post date: [19 February 2021 03:15 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274/1 "2021-02-19T03:15:24Z")

</div>

Can you update the values of a node instance from the runtime? I am looking to run data migration on existing nodes when they are loaded.

---

<div class="post-metadata">

### Author: ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)
#### Post date: [19 February 2021 07:06 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274/2 "2021-02-19T07:06:10Z")

</div>

Welcome to the forum.  
Can you give a specific example of what you want to do that we can better understand the requirement?

---

<div class="post-metadata">

### Author: ![zachowj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zachowj/32/37522_2.png) [@zachowj](https://discourse.nodered.org/u/zachowj)
#### Post date: [19 February 2021 07:54 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274/3 "2021-02-19T07:54:45Z")

</div>

I would like to run a function, `migrations`, on the config of a node. Having it modify the existing config. So if the user edits the node in the editor it will be populated with this modified data instead of what was loaded from the flows file.

My use case is over time some of my nodes have vastly changed from what they started as and it would be nice to update them to a new schema from the backend instead of having the user have to click on each node in the editor where I currently do this sort of thing inside the `oneditsave` method.

```javascript
function SampleNode(config) {
    // Is there some exposed method I can call here to edit the config from the runtime? RED.nodes.???
    const migratedConfig = migrations(config);
    RED.nodes.createNode(this,migratedConfig);
}

RED.nodes.registerType("sample",SampleNode);

function migrations(schema) {
    const newSchema = {
       ...schema,
       version: 1,
       newProperty: "randomValue"
    };

    return newSchema;
}

```

Config

```json
{
"id": "73ad87bc.f4be28",
"type": "sample",
"name": "",
"wires": [[]]
}

```

---

<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: [19 February 2021 13:01 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274/4 "2021-02-19T13:01:10Z")

</div>

Anything is _possible_, whether wise is a different matter 😁

It is theoretically possible to run a script to manipulate your flows json file directly. It would take some careful working out due to the necessities of JSON formatting.

I goes without saying that Node-RED should be offline when doing this and that you should always have at least one backup before you start.

---

<div class="post-metadata">

### Author: ![zachowj](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zachowj/32/37522_2.png) [@zachowj](https://discourse.nodered.org/u/zachowj)
#### Post date: [19 February 2021 21:07 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274/5 "2021-02-19T21:07:27Z")

</div>

Yes, using an external script I always an option. I have already provided one to users for removing some information from exported flows while sharing. [https://zachowj.github.io/node-red-contrib-home-assistant-websocket/scrubber/](https://zachowj.github.io/node-red-contrib-home-assistant-websocket/scrubber/)

But I was looking for an option that is more seamless for the user.

My latest thought was if there's not an exposed method to update a flow config, that I might fake a post to `/flows` and update them that way.

---

<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: [20 April 2021 21:07 UTC](https://discourse.nodered.org/t/modify-the-node-instance-definition-from-the-runtime/41274/6 "2021-04-20T21:07:44Z")

</div>

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