Crypto

crypto.randomUUID()

Creates a random version 4 UUID. Use as an identifier, not as proof that the caller may access the associated resource. Check shape rather than exact value. Tested on Node.js 22.16.0. Example output (one line per entry): ["36 4 true"].

Formal Syntax & Structure

nodejs syntaxnodejs
crypto.randomUUID([options])

Parameters & Attributes

NameTypeDescription
optionsobjectEntropy cache configuration.

Return Value

string

UUID.

Working Example

Example Snippetnodejs
import { randomUUID } from 'node:crypto';const id = randomUUID();console.log(id.length, id[14], /^[89ab]$/.test(id[19]));
Node.js Reference