In this bog post, I want to show you how to generate a UUID easily using the crypto interface, and why it's important in secure contexts.
What is crypto Interface
The Crypto interface represents basic cryptography features available in the current context. It allows access to a cryptographically strong random number generator and to cryptographic primitives.
How to generate UUID
To generate a UUID with the crypto interface, you need to use the randomUUID()
const uuid = crypto.randomUUID();
console.log(uuid); // Output "36b8f84d-df4e-4d49-b662-bcde71a8764f"More
You should avoid using the Web Crypto API in insecure contexts, even though the Crypto interface is present in insecure contexts, as is the crypto property. In addition, the method randomUUID() is only available on secure contexts (HTTPS and localhost).
🔍. Similar posts
Fix "Vite: Permission denied" — quick node_modules fix (npm run dev)
31 Jan 2026
How to Set Your Local Branch to Track a Remote Branch in Git
30 Sep 2025
How to Create a Git Branch From origin/master
28 Sep 2025