Hello everyone,
In the last few days I have successfully integrated node-red into an existing express application.
Is there a way to add a custom node from this code base? So not by loading from a node folder from the user data directory?
I have tried the function: Node-RED
I am also not quite sure how to integrate the html documents with scripts programmatically.
Why do I want to do that?
I would like to access backend data in my custom nodes via existing repositories instances.
Hi @WuerzburgerMaetschke
You cannot register a full node programmatically; we only support the runtime loading the nodes itself.
But, you can set the nodesDir
setting you pass into the runtime to point at a directory on disk that contains the nodes you want to load. That can be within your application code, rather than the user directory. They will need to have a package.json
file etc to 'appear' like a full node module.
To install custom nodes what I do is create tarballs i.e. npm packages and then import them into Node-RED using the same API that the upload tgz file uses:
the endpoint for that is a POST to /nodes
with a single .tgz file as content. To verify that check your browser network traffic when doing a test upload.
That assumes that your embedding of Node-RED allows it to access that endpoint.
Ah, thx for the fast responses
.
I already switched to this path with the customized nodesDir, but i just wanted to check twice.
I also need to adjust my webpack config for moving the files unbundled to the nodesDir output folder transpilled to js and copy the html files and package.json to the output folder, too.
@gregorius Thank you for this interesting idea. If I have understood it correctly, you simply install the custom nodes as a tarball at program start via the endpoint you mentioned.
I might give it a try.
I use that endpoint to develop custom nodes in node red. Each update to a custom node is simple reinstalled and I can test my changes.
Be aware that the endpoint does version checking, so to reinstall a custom node that already exists the tarball needs a new version.
Hi,
When using nodesDir, can it contains multiple folder ? I created a custom node from the exemple Creating your first node
I tried nodesDir with the path to the folder containing my custom node folder and tried with the custom folder path directly and the node was nowhere to be found. I checked in the palette manager and nothing too.
Did I miss something ?
EDIT : I needed to 'npm install ./src/lib/red-nodes/test' in my main application to make it work. I thought this step was optional if I specified 'nodesDir'.
I had a path issue at the beginning, so i first set the path of the user directory, and noticed where my flows were saved to.
something like:
userDir: path.join(__dirname, cfg.red.userDir),
gave me the correct locaiton i wanted instead of just my cfg.red.userDir path.
same worked then for my nodesDir.