DEV Community

Kitanga Nday
Kitanga Nday

Posted on

Easily create UUIDs without a package

So you want to create UUIDs but you don't want to download node-uuid or some other UUID generating library. Then I think you'll like the Web Crypto API.

See, this API comes with a method called randomUUID which generates a random and valid version 4 UUID.

Example:

const uuid = window.crypto.randomUUID(); // returns '5ac3544a-2c5e-4428-b948-41762b123e11'
Enter fullscreen mode Exit fullscreen mode

Hopefully, this comes in handy for you. And before you ask, browser support is amazing!

Image description

Top comments (0)