Can I use _msgid for naming temporary file

I want to create a temporary file with a unique name alongside an execution path in a node-red flow. I know that this would be safe:

  • Node1 - exec, calls mktemp, which creates a temporary file with a unique name
  • Node2, fills temporary file with content
  • Node3 - exec, calls executable which requires the content present in tempfile
  • Node4, deletes temporary file again

And in-between some change nodes to shuffle the data between fields as needed.

Now I'm considering to replace the call to mktemp by using a temporary file named "/tmp/nodered-" + msg._msgid. Is _msgid unique enough provided I take care in my flow that the same original message cannot be routed to my Node1-Node4 sequence through multiple paths?

Yes, it only contains two hex strings joined with a dot as far as I know. That should be valid on any filing system.

Is it unique enough? How is it created?

It would be unique enough for me if each _msgid is the result of running a good random number generator, or if it is some combination of a datetime and an atomic counter (to differentiate between multiple messages created in the same microsecond or similar).

It is a random number expressed in hex.

The only thing to watch out for is any node that (improperly) creates a new msg object rather then reuse the msg it received. That could lead to a new msgid being generated.

But if for the particular set of nodes you want to use, you see msgid is stable from end to end, then go for it.

Alternatively, add your own random property at the start that you have complete control over.


Perhaps you could also use this?

Though it produces a rather longer unique string like:



For the record, I had marked knolleary's reply as the solution because it answered my question and that's what I used in my first solution.

Later, I switched to using node-red-contrib-uuid as suggested by TotallyInformation just to be on the safe side.

1 Like