Creating Custom Config node and adding reference of that config to all normal node created

Hi All,

I have created more than 10 nodes for different purposes, in which I am supplying the ClientId and ClientSecret to connect the API in all node. This I have achieved, but now the new requirement to put both common input in config so to input once and use in all global.

I want to create a custom config that will have ClientId and ClientSecret. which will be used in all normal custom node created. for the purpose of reusability in global context.

Please help me to achieve this.

The process is documented in the Node-RED docs. You could also look at the code for one of the many nodes that use it.

I published a test node that also includes it. The test node was put together to remind me of all of the various parts of a node and is heavily documented.

Hello Sir,

I have gone through above mentioned project and implemented in my project. But I am getting invalid Properties error on node
invalidproprtieserror.pdf (177.6 KB)

image ---> This is config node with name GetAuthentication.

----> These are all nodes where want to implement config node.

Could you please help on this.

I can't really tell anything from the supplied information. However, it took me several goes to get a working config node as well. There are several things you have to align for them to work. I can only suggest going back to the docs and following them very carefully, comparing against what you've done.

There is something in package.json you have to do, then specifics in both the html and js files both for the config node and in the nodes that want to use the config node.

Hi, can I ask, instead of all these individual nodes, have you considered having just one node with a drop down that the user selects what to get e.g. "GetAllMachines" or "GetMachineLastJob" etc etc.

This makes it easier for the user to automate operations (especially if you let the user pass in the "function" via a msg property.

e.g. the user might want to trigger your node with a msg like this...

msg.topic = "GetAllMachines"
return msg;

or

msg.topic = "GetMachineLastJob"
return msg;

Thank You Sir,

I will look deeply in all files once again.

Thanks for your suggestion.

Yes this also might be the solution for this. But all nodes code will have to be in one html and js file that might look bad. and changes also will be tedious job.

So put all separate nodes with there functionality, And it is the requirement also.

And I will recommend your solution also. But for now could you please help with config node, if you have a better way to achieve this. I just want to put clientId and clientSecret in config node and to access in all normal node.

Your help is much appreciated sir.

Thanks

You can, of course, leveage Node.js's native module support in your js file. In uibuilder, I have two external modules, one that contains non-Node-RED specific functions and the other where the functions require references to the RED object. These modules can be required into multiple js files of course an d Node.js takes care of only loading them once.

I would disagree - maintaining 10 different node is harder than 1 with a dropdown.

Also, I suspect if the request is for "separate nodes" i suspect the end user either doesn't understand the benefits they will miss out on OR the specification is unclear OR they will ask you to re-do it when they realise they cannot easily automate it.

And, as @TotallyInformation points out, the "functionality" can easily be kept in separate JS files and required into your node.

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