1

In my Node.js application I need a unique ID - it need to be a UUID or something like that, just unique (auto-incrementing a number is not unique enough ;-)).

At the moment I am using node-uuid, but I'm curious whether there is a way of how to achieve this without an additional module.

I though about using a timestamp, but that's not unique (as several calls to +Date() may happen in the same millisecond.

Any other idea on how to achieve this?

Golo Roden
  • 140,679
  • 96
  • 298
  • 425
  • I think nobody would create node-uuid if there was any other native solutions to solve this problem... – Marcin Olichwirowicz Jan 13 '14 at 17:32
  • 1
    https://gist.github.com/jed/982883 – Robert Harvey Jan 13 '14 at 17:34
  • 1
    Maybe take a look here: http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript – basilikum Jan 13 '14 at 17:38
  • If you don't care about RFC compliance (or other standards compliance), combining a random # (32+ bits of randomness) and a timestamp (unique value changes every 1-16 msecs) is a decent start. E.g `Date.now().toString(36) + Math.random().toString(36).substr(2)` – broofa Jan 15 '14 at 00:33

0 Answers0