How to create a definition file to use in multiple nodes

I would like to create a definition file containing general information such as path, constants, ... to use in multiple nodes,
I think it is related to global variable, but don't know how is it good.
Can you please suggest way how can I do this?
Any hint will be great.

You can create a pseudo node with no Editor component where you can share objects including code. Or you can use a configuration node that you share between your nodes. My node-red-contrib-jktesting GitHub contains examples of both.

1 Like

It depends if you want this general information to be available in the editor or the runtime.

In the runtime side, if your multiple nodes are all in the same npm package, then you can include an extra JavaScript file in your package that each node requires to load in those constants etc.

It's slightly more involved to do that in the Editor side, but as @TotallyInformation has alluded to, it can be done in a slightly hacky way.

1 Like

Thank you for you support!
I have node-red-contrib-jktesting node installed already,
but don't understand how to use it yet, I will learn more...

1 Like

I'm trying to do something like in the definition file that contains general information like path = '/ home/', limit_number = 3, ...
when click start node, nodes in the same or different flow can see. and get this general information without having to specify it many times at the nodes.

is this information something that the user should be able to change? If yes, then I would recommend a configuration node.
Another option would be to specify this in the settings file, if these are constants that are rarely changed

1 Like

Yes, exactly what I want to do.
Can you tell me how to do it or just give me a reference link?
Am I correct in the following link?

do you want to do the first or the second?
Configuration nodes

If you want settings, then RED.settings gives you access to the settings of your settings file (e.g. in ~/.node-red/settings.js)

1 Like

Thank you all.

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