Skip to Content
Getting StartedInstallation

Last Updated: 3/9/2026


Installation

Choose the installation method that matches your project setup.

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 nanoid
import { nanoid } from 'nanoid' const id = nanoid()

CommonJS

For projects using require() and CommonJS modules.

Works out of the box:

npm install nanoid
const { nanoid } = require('nanoid') const id = nanoid()

Node.js 20

Requires experimental flag:

node --experimental-require-module your-script.js

Node.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@3

JSR (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/nanoid
import { nanoid } from '@sitnik/nanoid' const id = nanoid()

Deno

deno add jsr:@sitnik/nanoid

Or 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