Function to generate UUID or similar


Is there any way to via a function or similar generate a unique id string similar to UUID 4 or another way to create a unique id?

Kind regards

One simple solution could be this:


Depending on how long you want it you can simply add or remove a few 9.

If you want to avoid the chance of a collision and alphanumerical you can combine the current date and a random string like this:

{{(+new Date).toString(36).slice(-5) + Math.random().toString(36).substr(2, 5)}}
1 Like

Thanks it will work for now, but would it possible to add function for a full UUID128-bit in the future?

Should i add it the feature request?

Kind regards

Yes please add it as a feature request.

1 Like

As the uuid npm-package is now by default a dependency of n8n as it gets used to generate unique paths for the webhook, it is now possible to create uuids in the Function-Node for example like this:

const uuid = require('uuid');
items[0].json.uuid = uuid.v4();
return items;

That will however only work if the following environment variable got set:

1 Like