Skip to Content
📋 ReferenceCli Reference

Last Updated: 3/12/2026


CLI Reference

Nanoid includes a command-line interface for generating IDs directly in your terminal. No installation required—just run it with npx.

Basic Usage

Generate a single ID with default settings (21 characters):

$ npx nanoid npx: installed 1 in 0.63s LZfXLFzPPR4NNrgjlWDxn

The first run installs the package temporarily. Subsequent runs are faster.

Custom Size

Use the --size or -s flag to specify ID length:

$ npx nanoid --size 10 L3til0JS4z

Custom Alphabet

Specify a custom alphabet with --alphabet or -a. When using a custom alphabet, --size is required:

$ npx nanoid --alphabet abc --size 15 bccbcabaabaccab

This generates a 15-character ID using only the letters a, b, and c.

Help

Display usage information:

$ npx nanoid --help Usage $ nanoid [options] Options -s, --size Generated ID size -a, --alphabet Alphabet to use -h, --help Show this help Examples $ nanoid -s 15 S9sBF77U6sDB8Yg $ nanoid --size 10 --alphabet abc bcabababca

Use Cases

Shell scripts:

filename="upload-$(npx nanoid -s 10).jpg" echo $filename

CI/CD pipelines:

build_id=$(npx nanoid --size 8) docker tag myapp:latest myapp:$build_id

Quick testing:

curl -X POST https://api.example.com/items \ -d "id=$(npx nanoid)"

Requirements

The CLI requires Node.js to be installed on your system. Nanoid itself doesn’t need to be installed—npx handles it automatically.

What’s Next