crypto.randomUUID()

Generates a random RFC 4122 version 4 UUID.

Since Node 14.17 Spec ↗

Syntax

crypto.randomUUID([options])

Parameters

NameTypeRequiredDescription
options object No `{ disableEntropyCache: true }` to skip the prebuffered entropy cache.

Returns

string — A 36-character UUID string.

Examples

import { randomUUID } from 'node:crypto';

console.log(randomUUID());
Output
3f1c8e2a-7b4d-4a6e-9f12-2c5d8e9a1b3c
import { randomUUID } from 'node:crypto';

const order = { id: randomUUID(), total: 49.99 };
console.log(order.id.length);
Output
36

Notes

Cryptographically secure and ideal for IDs and tokens. Also exposed as the global `crypto.randomUUID()` (Web Crypto). For database keys consider UUIDv7 (time-ordered) if available in your stack.

See also