flake

flake (GitHub: chilts/flake, License: MIT) can generate practically unique
approximately sortable IDs in a distributed environment, similiar to
Twitter’s Snowflake.

1
npm install flake

Use in distributed environments where you don’t have a central service
which can be a single point of failure – perfect when you want
everything to be redundant and independent of each other. Flake Id is
made up of timestamp-counter-pid-macaddress

1
2
3
4
5
6
7
> var flake = require('flake')('eth0');
> console.log(flake());
013b829b1520-0000-18f0-984be1b8b104
> console.log(flake());
013b829b1527-0000-18f0-984be1b8b104
> console.log(flake());
013b829b1527-0001-18f0-984be1b8b104

In the example above, eth0 is used for machine’s network interface,
but this is not guaranteed to work on your machine. You need to change
it to something which exists on your machine. It’s easy to find it on
your machine using ifconfig or something similiar.

There are plenty of examples and information on the
github page.

Post navigation

Leave a comment

Leave a Reply

Your email address will not be published. Required fields are marked *