Last Updated: 3/9/2026
Installation
Choose the installation method that matches your project setup.
ESM (Recommended)
For modern JavaScript projects using ES modules with import statements.
Nano ID 5 works with ESM projects in Node.js, browsers, and bundlers like Vite, Webpack, or Rollup.
npm install nanoidimport { nanoid } from 'nanoid'
const id = nanoid()CommonJS
For projects using require() and CommonJS modules.
Node.js 22.12+ (Recommended)
Works out of the box:
npm install nanoidconst { nanoid } = require('nanoid')
const id = nanoid()Node.js 20
Requires experimental flag:
node --experimental-require-module your-script.jsNode.js 18
Use dynamic import:
let nanoid
module.exports.createID = async () => {
if (!nanoid) {
({ nanoid } = await import('nanoid'))
}
return nanoid()
}Legacy Projects
For older Node.js versions, use Nano ID 3.x (still supported):
npm install nanoid@3JSR (JavaScript Registry)
JSR is a modern alternative to npm with open governance. Works in Node.js, Deno, Bun, and other runtimes.
npx jsr add @sitnik/nanoidimport { nanoid } from '@sitnik/nanoid'
const id = nanoid()Deno
deno add jsr:@sitnik/nanoidOr import directly:
import { nanoid } from 'jsr:@sitnik/nanoid'CDN (Quick Hacks)
For quick prototypes and experiments. Not recommended for production due to performance and reliability concerns.
import { nanoid } from 'https://cdn.jsdelivr.net/npm/nanoid/nanoid.js'
const id = nanoid()Production Warning
⚠️ CDN imports have several drawbacks:
- Slower load times (extra network request)
- No version pinning guarantees
- Dependency on third-party CDN uptime
- No offline development
For production apps, use npm/JSR installation.
Verify Installation
Test your installation:
import { nanoid } from 'nanoid'
console.log(nanoid())
// Should print something like: "V1StGXR8_Z5jdHi6B-myT"Platform-Specific Setup
Some platforms require additional configuration:
- React Native - Requires polyfill for random number generation
- TypeScript - Works out of the box, with advanced type features available
- Webpack/Babel - May need transpilation config for monorepos
Next Steps
- Quick Start Guide - Generate your first IDs
- Core API - Learn the main functions
- Custom Alphabet - Customize your IDs