cuid2

Secure, collision-resistant unique IDs for JavaScript, built to resist guessing and horizontal-scale collisions.

Library
npm
v3.3.0
3,401 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
45 /100 Fair
Development Activity 32
Maintenance 4
Community 52
Maturity 52
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
71 /100 Good
Architecture 78
Code Quality 78
Innovation 72
Learning Curve 55

Cuid2 is a next-generation unique ID generator built as a security-conscious replacement for UUIDs and the original Cuid. Instead of relying on a single entropy source, it combines the current timestamp, a session counter, a host fingerprint, and cryptographically secure random values, then mixes them through a NIST-standard SHA3 hash so the output reveals nothing about how or when it was created.

The library ships as a tiny, dependency-light ESM package with zero async operations, making it safe to call in hot paths across Node.js and browser environments. It also includes a CLI (npx @paralleldrive/cuid2) for generating ad-hoc IDs and slugs from the terminal, and an isCuid validator for checking existing values. With over 19 million weekly downloads, it’s a common choice for primary keys, request IDs, and other identifiers that need to be generated client-side without a database round trip.

What You Get

  • createId() — a zero-config function that returns a 24-character, lowercase alphanumeric identifier ready to use as a primary key or public-facing ID
  • init(options) — a configurable factory that lets you set a custom id length (2-32 chars), a custom fingerprint, or a custom random function (e.g. a CSPRNG)
  • isCuid(id, options) — a validator to check whether a string matches the expected cuid2 shape and length constraints
  • A CLI (npx @paralleldrive/cuid2) for generating one or many ids or short slugs directly from the terminal, with an optional shell alias installer
  • TypeScript type definitions (index.d.ts) shipped in the package, so consumers get full type safety with no extra @types install

Common Use Cases

  • Generating primary keys for database rows created on the client before an insert, avoiding a round trip just to obtain an id
  • Producing public-facing resource identifiers (e.g. in URLs) that don’t leak creation order or timing the way sequential or k-sortable ids do
  • Creating short, human-shareable slugs (via a reduced length) for use cases like disambiguating usernames or short links
  • Generating request/correlation ids in distributed systems where multiple hosts must produce non-colliding ids without a shared counter or lock

Under The Hood

Architecture The library is a flat, single-module design centered on src/index.js, built as a small functional pipeline rather than a class hierarchy: createRandom picks between the Web Crypto API and Math.random as the entropy source, createEntropy and createFingerprint derive salt and host-identity strings, and init() closes over a counter, fingerprint, and random function to return a per-call id generator. The default createId export is a lazily-initialized singleton (via a small lazy(fn) wrapper) so fingerprint/counter setup is deferred until first use. The root index.js is a thin re-export layer over src/index.js, and bin/cuid2.js is a separate CLI entry point that imports the built index.js and translates argv flags into init() options. There is no deeper layering — changing the hash() function or the order entropy sources are concatenated in would change the shape of every id the library produces.

Tech Stack The package is distributed as ESM only ("type": "module" with an exports map) and depends on @noble/hashes for an audited SHA3-512 implementation and bignumber.js to convert hash bytes into a big integer for base36 encoding. A separate error-causes dependency is used only in the maintainers’ own release.js script, not in the published library code. Build/release tooling includes ESLint 9 (flat config) with Prettier, a Husky pre-commit hook, and release-it for versioning. The repository also bundles a small Next.js app (next.config.js, pages/) used for a companion demo/visualization site (histogram and randogram pages), which is excluded from the published npm package via the files allowlist in package.json.

Code Quality Tests live in src/index-test.js and src/bin-test.js, run directly with node using the riteway library’s given/should/actual/expected assertion style rather than a full test-runner framework. Beyond unit tests, the repo includes src/collision-test.js and src/histogram.js, which generate millions of ids across parallel processes and check the output distribution for statistical bias — a notably more rigorous validation approach than most id-generation libraries ship with. Hand-authored TypeScript definitions (index.d.ts) cover the public API and are checked against the test file via a dedicated tsc script. A GitHub Actions workflow (.github/workflows/ci.yml) runs checks on push, and ESLint/Prettier/Husky enforce style locally. Error handling is minimal but explicit — init() throws a descriptive Error when an invalid length is requested.

What Makes It Unique Cuid2’s real innovation isn’t a new algorithm class but a deliberate entropy-composition strategy: it mixes a timestamp, a randomly-seeded session counter, a hashed host fingerprint, and CSPRNG output through a single NIST-standard hash function, and is intentionally tuned to not be maximally fast, since very fast id generation makes brute-force collision- and pattern-hunting attacks cheaper. That’s a different design goal than speed-optimized alternatives like nanoid or UUID v4, which don’t treat generation speed itself as an attack surface. It’s best understood as a thoughtful, security-focused evolution of the original Cuid rather than a groundbreaking new technique, but it fills a specific, well-articulated niche that most alternatives don’t target.

Used by 17 apps in this directory

Rust
54%
Other

Cap

Team Chat · Video Conferencing

22,884

Open source Loom alternative with GPU-accelerated recording, instant share links, AI summaries, and full self-hosting via Docker Compose.

View details
89
Repo Health
81
Technical
64
Dependency
Built with
Rust 54%
TypeScript 42%
Updated 4 days ago
TypeScript
98%
Other

Formbricks

Analytics · Design Tools · Forms Surveys

13,031

Open-source experience management platform for in-app, website, email, and link surveys — privacy-first and fully self-hostable.

View details
93
Repo Health
81
Technical
67
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
91%
Apache 2.0

Helicone

AI Development · Analytics · Monitoring

6,182

An open-source AI gateway and LLM observability platform that routes requests to 100+ models while logging cost, latency, and full traces for every call.

View details
70
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 91%
Updated 2 weeks ago
TypeScript
90%
MIT

Kaneo

Product Management · Productivity · Project Management

9,250

Lightweight self-hosted project management that gives you kanban boards, GitHub sync, and full team collaboration without the enterprise bloat.

View details
87
Repo Health
81
Technical
70
Dependency
Built with
TypeScript 90%
Updated 5 days ago
TypeScript
98%
AGPL 3.0

Karakeep

Bookmarks Archiving

29,321

Self-hosted bookmark manager that captures links, notes, images, and PDFs with AI tagging, full-text search, and automatic archiving.

View details
88
Repo Health
76
Technical
66
Dependency
Built with
TypeScript 98%
Updated 5 days ago
TypeScript
99%
MIT

KeystoneJS

CMS · Developer Tools

9,982

The superpowered headless CMS for developers built with GraphQL and React

View details
92
Repo Health
81
Technical
64
Dependency
Built with
TypeScript 99%
Updated 4 days ago
TypeScript
97%
Other

Langfuse

AI Development · Monitoring

35,117

Open source AI engineering platform for LLM observability, prompt management, evaluation, and debugging — self-host in minutes or use Langfuse Cloud.

View details
92
Repo Health
81
Technical
65
Dependency
Built with
TypeScript 97%
Updated 4 days ago
TypeScript
78%
LGPL 3.0

Latitude

AI Agents · Monitoring

4,686

Open-source AI agent monitoring that catches what will break next before your users do.

View details
86
Repo Health
88
Technical
67
Dependency
Built with
TypeScript 78%
Rust 11%
Python 11%
Updated 1 weeks ago
TypeScript
96%
AGPL 3.0

Libra AI

AI Development · No Code Platforms

1,684

Open-source AI-powered platform that generates and deploys full-stack web applications from natural language prompts, built natively for Cloudflare Workers.

View details
31
Repo Health
71
Technical
68
Dependency
Built with
TypeScript 96%
Updated 1 years ago

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers