Deno ships a full standard library including UUID generation, making it one of the few runtimes with RFC 9562-compliant UUID v7 support out of the box. Unlike Node.js — which requires the uuid npm package for v7 — Deno provides @std/uuid via the JSR registry with no external dependency. This page covers UUID v7 in Deno applications: standard library usage, Fresh framework integration, Deno KV key patterns, and Deno Deploy edge workers.

Standard library usage

// Import from JSR (Deno's package registry)
import { v7 } from "jsr:@std/uuid";

// Generate a UUID v7
const id = v7.generate();
console.log(id); // "019236a7-b4f2-7000-8d3e-9c1a2b3d4e5f"

// Validate any UUID (v1–v8)
import { validate } from "jsr:@std/uuid";
console.log(validate(id)); // true

// UUID v4 via Web Crypto (built-in, no import needed)
const v4id = crypto.randomUUID();

The @std/uuid JSR package follows RFC 9562 for all supported versions. v7.generate() produces a monotonic-counter UUID v7 — successive calls within the same millisecond increment the counter field for strict ordering.

Fresh framework — route and resource IDs

Fresh is Deno’s full-stack web framework. In Fresh API routes, use UUID v7 for resource creation:

// routes/api/orders.ts
import { Handlers } from "$fresh/server.ts";
import { v7 } from "jsr:@std/uuid";

export const handler: Handlers = {
  async POST(req) {
    const body = await req.json();
    const order = {
      id: v7.generate(),          // UUID v7 primary key
      ...body,
      createdAt: new Date().toISOString(),
    };
    await db.set(["orders", order.id], order);
    return Response.json(order, { status: 201 });
  },
};

The Fresh documentation covers route handlers, middleware, and island components. UUID v7 IDs in API responses give clients a creation timestamp they can use for sorting without a separate field.

Deno KV key design with UUID v7

Deno KV supports composite keys. UUID v7 as the second key component gives time-ordered range scans:

const kv = await Deno.openKv();

// Store an event
const eventId = v7.generate();
await kv.set(["events", eventId], {
  type: "ORDER_PLACED",
  orderId: v7.generate(),
  payload: { items: 3 },
});

// List all events in creation order (oldest first)
const iter = kv.list<Event>({ prefix: ["events"] });
for await (const entry of iter) {
  console.log(entry.key[1], entry.value);
  // Keys are returned in lexicographic order = creation order for UUID v7
}

// List events after a specific time
const sinceMs = Date.now() - 3_600_000; // 1 hour ago
const sinceUuid = `${sinceMs.toString(16).padStart(12, "0").replace(/(.{8})(.{4})/, "$1-$2")}-7000-8000-000000000000`;
const recent = kv.list<Event>({ prefix: ["events"], start: ["events", sinceUuid] });

The Deno KV documentation explains key ordering, atomic transactions, and the list() selector API.

Deno Deploy edge workers

UUID v7 generation works identically in Deno Deploy edge workers — no configuration change needed:

// deploy/worker.ts — runs at the edge, ~30 locations worldwide
import { v7 } from "jsr:@std/uuid";

Deno.serve(async (req) => {
  const requestId = v7.generate(); // Time-ordered request ID for logging
  console.log(`[${requestId}] ${req.method} ${new URL(req.url).pathname}`);

  const response = await handleRequest(req);
  response.headers.set("X-Request-Id", requestId);
  return response;
});

Using UUID v7 as a request ID header means distributed logs can be sorted chronologically by the X-Request-Id value alone, without relying on timestamps from multiple edge nodes that may have clock drift. The Deno Deploy documentation covers global deployment and environment variable configuration.

Comparing Deno, Node.js, and Bun

FeatureDenoNode.jsBun
Built-in UUID v4crypto.randomUUID()crypto.randomUUID() (v19+)crypto.randomUUID()
Built-in UUID v7@std/uuid (standard lib)Not built-inNot built-in
UUID v7 packagejsr:@std/uuiduuid npmuuid npm
Package registryJSR + npmnpmnpm

Deno’s JSR-first approach means @std/uuid is versioned and auditable — the package source is visible at jsr.io/@std/uuid.

Further reading

External references

Frequently asked questions

Does Deno have a built-in UUID v7 generator?

Deno's standard library includes @std/uuid which provides v7.generate() for RFC 9562-compliant UUID v7 generation. Import it with import { v7 } from "jsr:@std/uuid". For UUID v4, Deno also exposes the browser-compatible crypto.randomUUID() globally without any import — available since Deno 1.17. The @std/uuid package on JSR documents all available version generators.

How does UUID v7 improve Deno KV key design?

Deno KV stores entries under lexicographically ordered keys. UUID v7 keys sort by creation time, so iterating a key space like ["orders", uuid_v7] naturally returns records newest-to-oldest or oldest-to-newest. UUID v4 keys require a separate created_at secondary index to achieve the same ordering. The Deno KV documentation covers key ordering and range iteration with kv.list().

Can I use UUID v7 in Deno Deploy edge workers?

Yes. Deno Deploy runs Deno standard library code natively — import { v7 } from "jsr:@std/uuid" works without modification in edge workers. UUID v7 generation is pure CPU computation with no I/O, so it adds negligible latency to edge responses. Deno Deploy's deployment documentation covers the Web Crypto API availability which backs UUID generation.