A tiny, secure, URL-friendly unique string ID generator for JavaScript, designed as a modern alternative to UUID.
Nano ID is a minimal, secure, and URL-friendly unique string ID generator for JavaScript. It solves the problem of generating collision-resistant identifiers that are smaller and faster than traditional UUIDs, using cryptographically secure random bytes and a larger alphabet to pack more entropy into fewer characters.
JavaScript developers building web applications, APIs, databases, or distributed systems who need reliable, secure, and compact unique identifiers for resources like database entries, session tokens, or URL slugs.
Developers choose Nano ID for its combination of security (via hardware random generators), tiny footprint (118 bytes), and excellent performance, offering a modern, drop-in replacement for UUID v4 with better defaults and fewer dependencies.
A tiny (118 bytes), secure, URL-friendly, unique string ID generator for JavaScript
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
At only 118 bytes minified with zero dependencies, Nano ID minimizes impact on application bundle size, as emphasized in the README's comparison with UUID packages.
Uses hardware random generators (Node.js crypto, Web Crypto API) for unpredictability, avoiding the security pitfalls of Math.random() and ensuring safe IDs for sensitive use cases.
Generates 21-character IDs using a larger alphabet (A-Za-z0-9_-), reducing size from UUID's 36 characters while maintaining similar collision probability, ideal for web addresses.
Benchmarks in the README show competitive generation speeds, often outperforming alternatives like uuid v4, making it efficient for high-throughput applications.
Supports custom alphabets, sizes, and random generators via customAlphabet and customRandom, allowing tailored ID generation for specific needs.
CommonJS usage requires Node.js 22.12 or 20 with experimental flags, and Node.js 18 needs dynamic imports, adding setup complexity for older projects.
Requires a polyfill like react-native-get-random-values for secure random generation, introducing an extra step and dependency for mobile development.
The README explicitly warns against using Nano ID for React key props due to consistency issues, limiting its utility in common UI patterns.
Secure ID generation relies on hardware randomness, making it unsuitable for deterministic scenarios like testing without custom random generators, which aren't guaranteed across versions.