Alternative Method for Supplying Custom Nodes in Node-RED

I've been working on a solution that involves using custom nodes in Node-RED. Initially, I set up my project with pnpm and had custom modules that shared dependencies within a monorepo. However, I've run into compatibility issues with how Node-RED loads modules when using this approach.

My custom nodes consist of some HTML and a function that is passed the RED object. I'm wondering if there's another way to supply custom nodes without packaging them as separate node modules.

Ideally, I'd like to do something like this:

RED.start();
myCustomNode(RED); // Start my custom nodes

Is this approach possible, and if so, what would be required to make it work with Node-RED's runtime?

Any insights or guidance on this matter would be greatly appreciated. Thank you in advance!

RED.nodes.registerType("lookup-advance", ... );
After running this. How could I supply the supporting HTML for the ui?

Not really clear what you are trying to do. The startup of Node-RED is complex but only uses standard CommonJS requires. So if that isn't working with pnpm, I would say that is down to something that pnpm is doing different to standard.

The other way to run Node-RED is to embed it in your own Node.js app. This is documented as far as I remember and I think I've even done it in the dim and distant past. Not for many years though.

For custom nodes, Node-RED's loading is necessarily complex as it has to include the runtime code and then various parts of that code get executed at different points in the startup. I even created a dummy set of nodes that let me explore that process with debugging info. You can find the jktesting nodes on my GitHub.

That is only the part of the Node that runs in the Editor. It isn't the runtime part of your node which is pure node.js JavaScript.

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