Gathering detailed insights and metrics for node-ip-snowflake
Gathering detailed insights and metrics for node-ip-snowflake
Gathering detailed insights and metrics for node-ip-snowflake
Gathering detailed insights and metrics for node-ip-snowflake
npm install node-ip-snowflake
Typescript
Module System
Node Version
NPM Version
73.6
Supply Chain
97.7
Quality
75
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Total Downloads
709
Last Day
1
Last Week
1
Last Month
11
Last Year
54
4 Stars
13 Commits
1 Watching
1 Branches
1 Contributors
Minified
Minified + Gzipped
Latest Version
1.0.1
Package Id
node-ip-snowflake@1.0.1
Unpacked Size
53.30 kB
Size
18.93 kB
File Count
10
NPM Version
2.15.1
Node Version
0.10.48
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
-75%
1
Compared to previous week
Last month
1,000%
11
Compared to previous month
Last year
-52.2%
54
Compared to previous year
1
node-ip-snowflake
node-ip-snowflake is a node.js clone and some updateing for snowflake-uid.
It referenced the baidu's implementaton of https://github.com/baidu/uid-generator. But this generator is a simpler and non-db implementation, the default generator uses the last 16bit value of the ip address as the worker id, 32 bits for timestamp, and 15 bits for sequence. So it can generate 32768 sequence/second for each instance for about 128 years.
** Snowflake algorithm:** An unique id consists of worker node, timestamp and sequence within that timestamp. Usually, it is a 64 bits number(long), and the default bits of that three fields are as follows:
sign | delta seconds | worker node id | sequence |
---|---|---|---|
1 bit | 32 bits | 16bits | 15bits |
sign(1bit)
The highest bit is always 0.
delta seconds (32 bits)
The next 32 bits, represents delta seconds since a customer epoch(2019-01-01). The maximum time will be 128 years.
worker id (16 bits)
The next 16 bits, represents the worker node id, maximum value will be 65536
. Why set 16 bits instead of the 22 bits of baidu's implementation is because usually we set the CIDR of k8s env is /16. 16 bits can guarantee that each instance has an unique worker id. If you can set the network CIDR to /24, you can increase the worker id bits, and decrease the time bits and sequence bits.
sequence (15 bits)
the last 15 bits, represents sequence within the one second, maximum is 32768
per second for one instance by default.
you can change the last three bits(delta seconds, worker id, sequence) by yourself depending your network settings, (total bits must equals to 64).
// only run example
npm install
node examples/example.js
npm i node-ip-snowflake
// in package.json
.....
"dependencies": {
......
"node-ip-snowflake": "^1.0.1"
}
.....
//only run snowflake nextId with default setting, and get ID in HEX 10.
var snowflake = require('node-ip-snowflake').Snowflake;
var id = snowflake.nextId(); // use default setting
console.log(id);
//only run snowflake nextId with default setting, and get ID in HEX 36.
var snowflake = require('node-ip-snowflake').Snowflake;
var id = snowflake.nextId(36); // use default setting
console.log(id);
//using custom settting.<br>
var snowflake = require('node-ip-snowflake').Snowflake;<br>
let config = {
timeBits: 32,
workerBits: 16,
seqBits: 15,
ip: '10.10.9.10',
beginTime: "2019-01-01"
};
snowflake.init(config);
var id = snowflake.nextId(16); // return a ID in HEX 16
console.log(id);
(important: whatever how you change the three configuration abouve, the sum of workerBits+timeBits+seqBits should be 63)
attention: beginTime should not be changed after it has been setted, and started to generate ID in your production env. otherwise you might get the same ID.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 0/13 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Score
Last Scanned on 2025-01-20
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More