Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Short id generator. Url-friendly. Non-predictable. Cluster-compatible.
branch: master

shortid Build Status shortid

Amazingly short non-sequential url-friendly unique id generator.

ShortId creates amazingly short non-sequential url-friendly unique ids. Perfect for url shorteners, MongoDB and Reddis ids, and any other id users might see.

  • By default 7-14 url-friendly characters: A-Z, a-z, 0-9, _-
  • Non-sequential so they are not predictable.
  • Supports cluster (automatically), custom seeds, custom alphabet.
  • Can generate any number of ids without duplicates, even millions per day.
  • Perfect for games, especially if you are concerned about cheating so you don't want an easily guessable id.
  • Apps can be restarted any number of times without any chance of repeating an id.
  • Popular replacement for Mongo ID/Mongoose ID.
  • Includes Mocha tests.


var shortId = require('shortid');



Mongoose Unique Id

_id: {
    type: String,
    unique: true,
    'default': shortId.generate


~/projects/shortid ❯ node examples/examples.js

Real World Examples

shortId was created for Node Knockout 2011 winner for Most Fun Doodle Or Die. Millions of doodles have been saved with shortId filenames. Every log message gets a shortId to make it easy for us to look up later.

Here are some other projects that use shortId:

  • bevy - A simple server to manage multiple Node services.
  • capre - Cross-Server Data Replication.
  • cordova-build - an alternative to phonegap build that runs on your servers/agents.
  • couchdb-tools - A library of handy functions for use when working with CouchDB documents.
  • CleverStack/clever-email - E-mail system for CleverStack.
  • CloudTypes - JavaScript end2end implementation of the Cloud Types model for Eventual Consistency programming.
  • dnode-tarantula - an asynchronous rpc and event system for node.js based on dnode-protocol and TCP sockets.
  • mongoose-url-shortener - A simple URL Shortening library for NodeJS using Promises/A+ results.
  • mozilla/smokejumper - The Smoke Jumper project is an effort to bring dead simple, secure, P2P file sharing to Firefox.
  • shortness - Node based URL shortener that uses SQLite.
  • file-db - Document database that uses directories and files to store its data, supporting nested key-value objects in named collections.
  • resume-generator - Resume Generator.
  • riffmint - Collaboration in musical space.
  • rap1ds/dippa - Dippa Editor – A web-based LaTeX editor



Returns an amazingly short non-sequential unique id.

Alias: shortId()


    _id: shortId.generate()
    name: ...
    email: ...


Default: 1


Choose a unique value that will seed the random number generator so users won't be able to figure out the pattern of the unique ids. Call it just once in your application before using shortId and always use the same value in your application.

Most developers won't need to use this, it's mainly for testing ShortId.

If you are worried about users somehow decrypting the id then use it as a secret value for increased encryption.




Default: '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ-_'


Change the characters used.

You must provide a string of all 64 unique characters. Order is not important.

The default characters provided were selected because they are url safe.


// use $ and @ instead of - an _
// any 64 unicode charcters work

About the Author @dylang @dylang

Hi! Thanks for checking shortid! My name is Dylan Greene. When not overwhelmed with my two young kids I enjoy contributing to the open source community. I'm also a tech lead at Opower.

Here's some of my other Node projects:

Name Description npm Downloads
grunt‑notify Automatic desktop notifications for Grunt errors and warnings using Growl for OS X or Windows, Mountain Lion and Mavericks Notification Center, and Notify-Send. grunt-notify
grunt‑prompt Interactive prompt for your Grunt config using console checkboxes, text input with filtering, password fields. grunt-prompt
npm‑check Check for outdated, incorrect, and unused dependencies. npm-check
rss RSS feed generator. Add RSS feeds to any project. Supports enclosures and GeoRSS. rss
xml Fast and simple xml generator. Supports attributes, CDATA, etc. Includes tests and examples. xml
changelog Command line tool (and Node module) that generates a changelog in color output, markdown, or json for modules in's registry as well as any public repo. changelog
grunt‑attention Display attention-grabbing messages in the terminal grunt-attention
observatory Beautiful UI for showing tasks running on the command line. observatory
anthology Module information and stats for any @npmjs user anthology
grunt‑cat Echo a file to the terminal. Works with text, figlets, ascii art, and full-color ansi. grunt-cat

This list was generated using anthology.


Copyright (c) 2014 Dylan Greene, contributors.

Released under the MIT license.

Screenshots are CC BY-SA (Attribution-ShareAlike).

Generated using grunt-readme with grunt-templates-dylang on Friday, November 7, 2014.

Something went wrong with that request. Please try again.