Hi
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
Mattias
Hi
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
Mattias
One simple solution could be this:
{{Math.floor(Math.random()*999999999)}}
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)}}
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
Mattias
Yes please add it as a feature request.
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:
NODE_FUNCTION_ALLOW_EXTERNAL=uuid
Thanks for sharing this, @jan. We just used this for our hackathon project
and here is me just using this: Online UUID Generator Tool with an HTTP request node.
We’re also planning on adding a convenience function to do this from expressions.
Looks like everyone is using a different approach.
Not sure if this could help, but here is the UuidV4 implementation in PHP
Would any of the examples work in the cloud hosted version?
Hey @Philip_Wiggins,
Using the api with an http request node would do the job.
You can also use the crypto module on n8n cloud like so to generate a UUID:
Result:
No external API required
You can simply use the crypto node:
Or does that not exist in the cloud version?
It is in there, I probably should have known this
It does actually and I constantly forget about it. That’s definitely the winner here
sorry to necro this post - @MutedJam is there a list of available dependencies in the cloud version?
Hi @A_B, I don’t have a definitive list right now but I believe it comes down to crypto and moment.js (and possibly request-promise, though iirc there was talk of removing this). Definitely not a lot, and there’s also no guarantee these will remain in place.
So if you need to use any npm modules self-hosting would be the way to go.
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.