Home > database >  Converting subflows into modules in node-RED
Converting subflows into modules in node-RED

Time:10-14

i'm new to node-red and docker. For my internship i was asked to convert a subflow into a module (in order to be in the palette of every instance of node-RED created) So, i've started with a little example showing how to add custom node as a module by following these steps (the node-RED is installed in a docker container):

  1. connecting to an ec2 machine

  2. going inside the container by executing the command docker exec -it mynodered /bin/bash/

and then i follow the steps as shown in this example https://techeplanet.com/how-to-create-custom-node-in-node-red/ to create the node and install it. After that i went to the "manage palette" to look for the recently installed module but it's not there ... If some one could help i will appreciate that. Thanks

CodePudding user response:

Firstly, Nodes installed on the command line with npm will not show up until Node-RED is restarted.

The problem with this, in your case is that you created the node in the docker container, under normal circumstances any files you created in the running container will be lost when you restart it. This is because containers do not persist changes.

Also in the docker container the userDir is not ~/.node-red but /data.

So when you restart the container the node will likely be lost and it also will not have been installed into the node_modules directory in the /data userDir unless you have /data backed by a persistent volume.

If you want to create a node on your local machine, you can test it locally by using npm to install it and then restarting the a local instance of Node-RED to pick up the new node.

You can then use the npm pack command to create a tgz file which you can upload to the remote instance via the Palette Manager to test it in the Docker container if needed.

For longer term use of this new node you have several choices:

  • Publish the node to public npm with suitable tags and have it added to the public list of Node-RED nodes as described in the doc. This will allow anybody to install the node. You should ONLY do this with nodes you expect anybody to be able to use
  • Build a custom docker container that installs your node as part of the build process. Examples of how to do this are here
  • Build a custom docker container with a custom settings.js that points to a private npm repo and catalogue service that will allow you to host custom nodes. A blog post touching on this is here

Secondly the guide you are following is for building Node-RED nodes, but not for converting a subflow into a node. While it is possible to completely reimplement the subflow from scratch it will probably require recreating lots of work done in the nodes in use, this is not really an efficient approach. There is on going work to build a tool that will automatically convert subflows into nodes but it is not ready for release just yet.

I suggest you join the Node-RED Slack or Discourse forum to be notified when it is available.

  • Related