UUID in JavaScript and Node.js

In modern JavaScript (browser and Node.js), the easiest way to generate a UUID is crypto.randomUUID(). It returns a Version 4 (random) UUID string and uses the platform's secure random source.

Browser

crypto.randomUUID() is supported in current Chrome, Firefox, Safari, and Edge. Call it when you need a new ID: const id = crypto.randomUUID();. No library required. For older browsers, use a polyfill or a library like uuid.

Node.js

In Node.js 19+ and 14.17+ (with the --experimental-global-webcrypto flag in older 14.x), globalThis.crypto.randomUUID() is available. In Node 15+, crypto.randomUUID() works without a flag. For older versions, use the uuid package from npm.

Validation

There's no built-in UUID parser in the browser. Use a regex (see How to validate a UUID) or call our API (GET /api/validate/{uuid} or POST /api/validate-bulk). Our validator runs in the browser and shows version and variant.

Summary

Prefer crypto.randomUUID() for v4 UUIDs in modern JS. For v1, v7, or validation, use the uuid package or our generator and API. To call the UUIDFactory API from TypeScript or Node.js, use the official client: uuidfactory-ts on GitHub · uuidfactory-ts on npm.

UUID in Python · How to validate a UUID · Developer's Corner