← all snippets

uuid-gen

Prints one random UUID v4 using Node's built-in crypto module. No dependencies — for when you need a quick unique ID for a test fixture, resource name, or trace ID.

JavaScript (Node) #09

Source

uuid-gen.js
#!/usr/bin/env node
// Print a random UUID v4.
'use strict';
const { randomUUID } = require('node:crypto');

console.log(randomUUID());

Input

None — takes no arguments, reads no config or environment.

Output

Prints a single UUID v4 string (e.g. xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx) to stdout, exit 0.

Usage

$ node uuid-gen.js
b0d3f6b0-6a3e-4b3a-9b0e-2f6a2b1c4d9e

Config

No configuration required.

Security notes

  • Uses Node's built-in crypto.randomUUID() (cryptographically secure RNG under the hood) — no third-party UUID package, no weaker Math.random()-based generation.
  • No input surface at all, so there's nothing to validate or sanitize.