nanoid

A tiny, secure, URL-friendly unique string ID generator for JavaScript and TypeScript

Library
npm
v6.0.1
26,937stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
85/100Excellent
Development Activity92
Maintenance84
Community64
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
90/100Excellent
Architecture90
Code Quality92
Innovation90
Learning Curve90

Nanoid is a tiny, secure, URL-friendly unique string ID generator for JavaScript. At just 118 bytes minified and gzipped, it has no runtime dependencies and generates IDs that are shorter than a UUID (21 characters by default) while offering a comparable collision probability, thanks to a larger URL-safe alphabet and hardware-backed randomness.

Beyond the default generator, Nanoid exposes customAlphabet and customRandom for teams that need a specific character set, ID length, or an alternate random source, plus a non-secure variant for environments without a hardware random generator. It ships with first-class TypeScript types, a small CLI for generating IDs from the terminal, and ports in over twenty other programming languages so the same ID scheme can be shared across a full stack.

What You Get

  • A zero-dependency nanoid() function that returns a 21-character URL-safe ID with collision odds comparable to UUID v4
  • customAlphabet() and customRandom() for generating IDs with a custom character set, length, or random source
  • A non-secure build for environments (like offline demos) that don’t need cryptographic randomness
  • First-class TypeScript declarations, including support for opaque branded ID types
  • A standalone npx nanoid CLI for generating IDs from the command line
  • Ports of the same ID algorithm in 20+ other languages for cross-stack ID consistency

Common Use Cases

  • Generating primary keys or record IDs in databases without relying on auto-increment or full UUIDs
  • Creating short, URL-safe identifiers for shareable links, slugs, or public resource IDs
  • Assigning client-side unique keys for React/Vue lists or optimistic UI updates
  • Producing session, request, or trace IDs for logging and distributed tracing

Under The Hood

Architecture — The package is deliberately small and single-purpose: index.js defines random(), customRandom(), and customAlphabet(), and composes the default nanoid export as customAlphabet(urlAlphabet); url-alphabet/index.js holds the compression-optimized default alphabet as a standalone module so it can be tree-shaken independently; non-secure/index.js re-implements the same API on top of Math.random() for non-cryptographic use; and bin/nanoid.js is a thin CLI wrapper that parses --size/--alphabet flags and calls straight into the library functions, keeping the CLI and library behavior identical.

Tech Stack — Nanoid has zero runtime dependencies and ships as native ESM ("type": "module") with a browser-specific entry (index.browser.js) mapped via the browser and react-native package.json fields, plus hand-written index.d.ts TypeScript declarations rather than a build step. Development tooling is modern and minimal: oxlint/oxfmt for linting and formatting, vite for the interactive demo, size-limit to enforce the documented byte budgets (118 B for nanoid, 207 B for customAlphabet), and tinybench/better-node-test (bnt) for benchmarking and testing, orchestrated through a pnpm workspace.

Code Quality — The test suite (test/index.test.js, test/non-secure.test.js, test/pool.test.js, test/bin.test.js, ~556 lines total) is run with bnt --coverage 100, enforcing full statement coverage on every change, and a simple-git-hooks pre-commit hook runs check-versions.js to keep versions consistent across package.json, jsr.json, and docs. The randomness code in index.js is unusually heavily commented, explaining the modulo-bias rejection sampling, the power-of-two fast path, and the string-pool optimization ported from the nope-id project, which makes an otherwise dense, performance-critical file easy to audit. Invalid input (negative size) throws an explicit RangeError rather than failing silently.

API Design — The public surface is intentionally tiny: nanoid() needs no arguments and no configuration to produce a safe ID, while customAlphabet() and customRandom() share a consistent (alphabet, defaultSize, [random]) shape for advanced cases, and TypeScript generics let consumers cast the result into an opaque ID type. The CLI mirrors the library’s flags one-to-one, and the README documents framework-specific guidance (React key warnings, React Native polyfills, PouchDB/CouchDB ID prefixing) that heads off common misuse before it happens.

Used by 108 apps in this directory

TypeScript
99%
Other

Activepieces

Automation · AI Assistants

23,887

Open-source AI automation platform that converts 280+ workflow integrations into MCP servers for LLMs, with no-code builders and TypeScript extensibility.

View details
92
Repo Health
85
Technical
65
Dependency
Built with
TypeScript99%
Updated today
TypeScript
88%
Other

AFFiNE

Productivity · Project Management · Note Taking

71,668

Write, draw, and plan in one infinite canvas — the open-source alternative to Notion and Miro that keeps your data yours.

View details
91
Repo Health
87
Technical
68
Dependency
Built with
TypeScript88%
Updated today
TypeScript
59%
Other

agenta

Developer Tools · Devops · AI Development

4,489

The open-source LLMOps platform unifying prompt engineering, evaluation, and observability for teams building reliable LLM applications.

View details
91
Repo Health
77
Technical
67
Dependency
Built with
TypeScript59%
Python39%
Updated today
TypeScript
72%
AGPL 3.0

APITable

Low Code Platforms · Databases

15,526

API-first collaborative spreadsheet-database platform that auto-generates REST APIs and lets teams build internal tools, CRMs, and dashboards without code.

View details
53
Repo Health
77
Technical
60
Dependency
Built with
TypeScript72%
Java22%
Updated 9 months ago
TypeScript
66%
Apache 2.0

Appsmith

Developer Tools · Automation · No Code Platforms

40,707

Open-source low-code platform to build admin panels, dashboards, and internal tools connected to any database or API.

View details
94
Repo Health
79
Technical
68
Dependency
Built with
TypeScript66%
Java22%
Updated today
TypeScript
49%
MPL 2.0

Artillery

Devops · Developer Tools

9,054

Cloud-scale load testing and functional testing for APIs, WebSockets, gRPC, and headless browsers, distributed across AWS Lambda or Fargate with zero infrastructure to manage.

View details
89
Repo Health
73
Technical
68
Dependency
Built with
TypeScript49%
JavaScript48%
Updated 5 days ago
TypeScript
100%
MIT

Botpress

AI Assistants · AI Development · Customer Support

14,872

The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.

View details
95
Repo Health
82
Technical
66
Dependency
Built with
TypeScript100%
Updated yesterday
TypeScript
49%
AGPL 3.0

BrowserOS

Browser · AI Assistants

13,248

The open-source agentic Chromium browser with native AI agents, MCP server, and visual workflow automation — your data never leaves your machine.

View details
87
Repo Health
82
Technical
69
Dependency
Built with
TypeScript49%
Rust22%
Python16%
Updated today
TypeScript
99%
Apache 2.0

Bubble Lab

Automation · AI Development

1,095

Open-core workflow engine for building AI-powered automations in TypeScript that run natively inside Slack — no context switching required.

View details
35
Repo Health
78
Technical
72
Dependency
Built with
TypeScript99%
Updated 3 months 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

Search