DEV Community

Cover image for Stop using external npm packages just to generate a UUID v4
Karthick Ajan G S
Karthick Ajan G S

Posted on

Stop using external npm packages just to generate a UUID v4

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();
console.log(uuid); // e.g., "f81d4fae-7dec-11d0-a765-00a0c91e6bf6"
Enter fullscreen mode Exit fullscreen mode

Why this matters for security
Unlike old-school math-based pseudo-random generators (⁠Math.random()⁠), ⁠crypto.randomUUID()⁠ uses the underlying operating system's hardware-backed entropy. It's fast, secure, and doesn't bloat your production bundle.
Need to generate UUIDs on the fly?
If you just need a batch of secure keys for configuration files, database testing, or environment variables, stop pasting your requirements into third-party online generators that process data on backend servers.
I built a completely offline, zero-server utility to generate these instantly in your browser:
👉 Secure Browser UUID Generator
It runs 100% client-side via the Web Crypto API, meaning your generated IDs never touch a network loop. Part of a larger privacy-first suite of tools at cipherkit.app.

Top comments (0)