Modify code of a node and use it

Hi all,

I need to modify a line of code of the node “modbus-serial” and include it on my home assistant installation.

I tested the modification on a PC where Node-Red runs locally, so it is easy to modify.
However, in Hassio, I don’t know where the source code files are stored.

Thanks

You create a custom component for it. You don’t modify the running hassio code.

How can I create a new custom component for Node-red? I downloaded the full original code and then I modified. I placed into the folder config/Node-red/nodes/ but doesn’t work.

I apologize, I read the OP as modifying the code for Home Assistant, but what you are asking has nothing to do with Home Assistant.

https://nodered.org/docs/creating-nodes/

Thanks! I already have the node created (because is a modification of an existing one). What I need is to replace/install it in the node-red installation of hassio.

You need to make it a DIFFERENT node and install it in the node_modules. You don’t modify running Docker containers.

And, where do I have to place the folder with the code? config/Node-red/nodes/?
And, additionally, I guess I have to tell somewhere to Node-red to use my code instead of the original.

you need to install them

If you do it properly, and create a custom node, it will be named differently, and node red will just pick it up. A friend of mine made a custom node for me from another node, I npm installed it from github, and it shows up as a different node.

I can do that you refers in a local installation. It is more or less easy. But, how can I do in Hassio if I cannot exec npm? Or at least I don’t know how to do it

You need to get inside the container and npm install. Portainer, CLI over SSH, keyboard/monitor plugged into your hassos device, etc.

Lots of ways to do this.

Great! Sounds good. I will try.
Many thanks for your help!

Hi again,

I entered using SSH Web terminal add-on and I see all the files of Hassio but I cannot find the node-red add-on files. Are they in another container?
In Portainer there is an image of Node-red add-on, is it possible to modify it? How?
Thanks

I told you what you needed to do.

You need to get inside the container and npm install.

Node Red itself is inside a container, yes. You aren’t supposed to be looking for node red files, you’re supposed to be getting into the container…

YOU DO NOT MODIFY DOCKER IMAGES

You can use Option: npm_packages in the add-on configuration.

This will only work if they are hosting their code somewhere like npmjs

Thanks.

I have been trying with Portainer but unfortunately I cannot find the container of node-red. I tried other options in node-red add-on: npm packages options, command options, etc. but doesn’t work as I need.

I just need to modify a line of the code of one node-red module. That’s all.

There is a setting for your Portainer add-on config that will allow you to see the other add-ons.

This is why I will not use HassOS/Supervised blah blah. NO CONTROL!

Great!! I found that at Settings. Just click on “remove” the addon filter and all the containers appeared.

Now I have access to the files, what is good for me. But, now the problem is that after modifying, if the system reboots, the modification does not remain because the system loads the image again. So, the solution should pass by modifying the image.

Thanks all for your support

But modifying the running image is what you are already doing. NPM install inside the correct path and it will stay forever, but you need your custom node hosted somewhere.

Yes, but I just wanted to modify one line of a module. I need to “npm stop” and “npm start” to make the changes available but those commands are not allowed.
Well… I will continue trying.