JavaScript UUID Generator
Generate a UUID instantly, then copy ready-to-use JavaScript code - both the native browser API and the popular uuid npm package.
Generate a UUID in JavaScript
Native browser / Node.js API (no dependency)
// Works in all modern browsers and Node.js 19+ const id = crypto.randomUUID(); console.log(id); // e.g. 3fa85f64-5717-4562-b3fc-2c963f66afa6
Using the uuid npm package (v1, v4, v7)
npm install uuid
import { v1 as uuidv1, v4 as uuidv4, v7 as uuidv7 } from 'uuid';
uuidv4(); // random
uuidv1(); // time-based
uuidv7(); // sortable, timestamp-based
Validate / parse a UUID
import { validate as uuidValidate, version as uuidVersion } from 'uuid';
uuidValidate('3fa85f64-5717-4562-b3fc-2c963f66afa6'); // true
uuidVersion('3fa85f64-5717-4562-b3fc-2c963f66afa6'); // 4
// Or with a simple regex (no dependency)
const UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
UUID_RE.test('3fa85f64-5717-4562-b3fc-2c963f66afa6'); // true
Nil UUID
const NIL_UUID = '00000000-0000-0000-0000-000000000000';