How to generate unique node ID when creating a flow via node-red API

Hello,

I would like to create a flow by using nodered API with this guide https://nodered.org/docs/api/admin/methods/post/flow/

Actually my plan is to copy paste an existing flow with only few modifications (serial request properties + global variable properties). This is to allow the user of the app to connect several serial devices of the same brand and model.

However I need to generate unique ids for the nodes included in this new flow.

Is there a way to ask nodered to generate a unique node id ?
Or should I generate a random id and parse all the flows to be sure it's not already used ?
Is there no risk that node-red use this randomly generated id in the future ?

Thanks for your help

2 Likes

Hi Charlotte, I had the same problem as you. I have found that IDs are generated with this JScript function (1 + Math.random () * 4294967295) .toString (16);

You can find it on file @node-red/util/lib/util.js, function generateId()

I hope it is useful for you
Ciao

1 Like

Hi,
Thanks.
Finally I used uuid JS library.
I found we can use JS library by adding them in settings.js file

can you teach me how did you do this ?
im interested in the same thing :slight_smile: also there is ui involved, generate new ui groups/subgroups.

many thanks