For years, the go-to move for generating a UUID in Node.js or the browser was installing the uuid package.

But if you are targeting modern environments, you can ditch the extra dependency entirely. Modern browsers and Node.js (19+) have native cryptographic support built right into the crypto global module.

Here is how you generate a cryptographically secure UUID v4 natively:

// Native Web Crypto API (Runs in browser and modern Node.js)

const uuid = crypto.randomUUID();