Need help with uid-safe?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.

About the developer

137 Stars 9 Forks MIT License 151 Commits 0 Opened issues


URL and cookie safe UIDs

Services available


Need anything else?

Contributors list


NPM Version NPM Downloads Node.js Version Build Status Test Coverage

URL and cookie safe UIDs

Create cryptographically secure UIDs safe for both cookie and URL usage. This is in contrast to modules such as uid2 whose UIDs are actually skewed due to the use of

and unnecessarily truncate the UID. Use this if you could still use UIDs with
in them.


$ npm install uid-safe


var uid = require('uid-safe')

uid(byteLength, callback)

Asynchronously create a UID with a specific byte length. Because

encoding is used underneath, this is not the string length. For example, to create a UID of length 24, you want a byte length of 18.
uid(18, function (err, string) {
  if (err) throw err
  // do something with the string


Asynchronously create a UID with a specific byte length and return a


Note: To use promises in Node.js prior to 0.12, promises must be "polyfilled" using

global.Promise = require('bluebird')
uid(18).then(function (string) {
  // do something with the string


A synchronous version of above.

var string = uid.sync(18)



We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.