Skip to content
Unique order id generator
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
lib format with prettier May 14, 2018
test format with prettier May 14, 2018
.gitignore Initial commit Nov 22, 2016
.prettierignore format with prettier May 14, 2018
.prettierrc update deps Nov 25, 2018
.travis.yml code Nov 22, 2016 Prettier changes Nov 25, 2018
license code Nov 22, 2016
package-lock.json update deps Nov 25, 2018
package.json update deps Nov 25, 2018


Build Status styled with prettier

(almost) unique order id generator

  • Generates order ids in the format xxxx-xxxxxx-xxxx, where x is a number (0-9).

  • Uses the current unix timestamp (13 digits) plus 1 random digit so it's unique down to the milisecond.

  • If your system generates 1,000,000 orders per day (homogeneously distributed), the probability of collision would be ~1%. The extra padding digit makes it even lower.

  • The timestamp is scrambled using a supplied key so the result doesn't appear as a timestamp.

  • Bonus: Since it's based on timestamp, we can get the time back from the order id (see api calls).


const orderid = require('order-id')('mysecret');
const id = orderid.generate();
// 3016-734428-7759

// 1479812667797


  • generate(date) - generates an order id. date is optional and can be anything that js Date constructor knows how to parse and it will use it as the time for the order id. otherwise, current date will be used.
  • getTime(id) - bonus feature :-) since it's based on a timestamp, it encodes the time the order was done. use this to get back the time of the order in unix timestamp format (you need to use the same key used to generate the order id).
You can’t perform that action at this time.