Nano ID: Secure URL-friendly unique string ID generator
Compact 21-character cryptographic IDs with URL-safe encoding.
Learn more about nanoid
Nano ID is a JavaScript library that generates unique string identifiers using cryptographic random number generation. It uses the Web Crypto API in browsers and the crypto module in Node.js to ensure unpredictability, with a custom algorithm that maintains uniform distribution across its alphabet. The library produces 21-character IDs with 126 random bits, comparable to UUID v4's 122 bits but in a more compact format. It is commonly used for database record IDs, session tokens, and other applications requiring collision-resistant unique identifiers.

Compact size
The library is 118 bytes when minified and brotli-compressed with no external dependencies. This is approximately 3 times smaller than the uuid/v4 package.
Larger alphabet encoding
Uses 64 characters (A-Za-z0-9_-) instead of UUID's hexadecimal format, reducing ID length from 36 to 21 characters while maintaining similar collision probability.
Uniform distribution algorithm
Implements a custom algorithm to ensure even distribution of characters across generated IDs, avoiding the bias that occurs with naive modulo-based approaches.
import { nanoid } from 'nanoid'
const id = nanoid() // => "V1StGXR8_Z5jdHi6B-myT"Fixes an infinite loop bug when customAlphabet is called with a size of 0.
- –Upgrade to avoid infinite loops if your code passes 0 as the size parameter to customAlphabet.
- –No breaking changes or new requirements are documented in this patch release.
Patch release correcting npm's latest tag after an accidental 3.x publish; no functional changes to the library.
- –Update to 5.1.5 to ensure you receive the correct latest version from npm's default tag.
- –Release notes do not specify any code changes, breaking changes, or new features in this version.
Patch release restoring React Native compatibility after a regression.
- –Upgrade if using React Native; previous version broke compatibility with the runtime.
- –Release notes do not specify the root cause or affected React Native versions.
Top in Developer Tools
Related Repositories
Discover similar tools and frameworks used by developers
ddt4all
Open-source Python application for vehicle diagnostics, ECU parameter modification, and CAN bus communication with Renault and Dacia cars.
code-server
Run VS Code on remote servers via browser.
excalidraw
React canvas library with encrypted collaborative drawing.
azure-cli
Cross-platform CLI tool enabling developers and administrators to manage Azure resources through intuitive commands and automation scripts.
nvm
nvm is a per-user, per-shell version manager for Node.js that allows switching between multiple installed Node versions from the command line. It works on any POSIX-compliant shell across Unix, macOS, and Windows WSL environments.