# node-snowflake.js

> snowflake 现实中很少使用到分布式, 因为最大可以支持1024个进程, 一个小型应用压根不会有部署那么多进程, 所以完全可以讲snowflake作为mysql 单机 ID 生成器

Latest version **2.0.1** (published 2020-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install node-snowflake.js
pnpm add node-snowflake.js
yarn add node-snowflake.js
bun add node-snowflake.js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.1 |
| Published | 2020-06-01 |
| First published | 2019-07-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >= 10.14.2 |
| Dependencies | 0 |
| Unpacked size | 11.6 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | ouyangbin |
| Keywords | snowflake |

## Links

- npm: https://www.npmjs.com/package/node-snowflake.js
- Repository: https://github.com/oyb81076/node-snowflake.js
- Homepage: https://github.com/oyb81076/node-snowflake.js#readme
- Issues: https://github.com/oyb81076/node-snowflake.js/issues
- npm.io page: https://npm.io/package/node-snowflake.js

## Recent versions

- 2.0.1 (latest) — 2020-06-01
- 2.0.0 — 2020-06-01
- 1.0.5 — 2019-08-14
- 1.0.4 — 2019-08-14
- 1.0.3 — 2019-08-13
- 1.0.2 — 2019-08-02
- 1.0.1 — 2019-08-02
- 1.0.0 — 2019-07-31

## README

# Twitter snowflake
snowflake 现实中很少使用到分布式,
因为最大可以支持1024个进程,
一个小型应用压根不会有部署那么多进程,
所以完全可以讲snowflake作为mysql 单机 ID 生成器


# Install
```
yarn add node-snowflake.js
or
npm install node-snowflake.js
```

## Usage
```ts
import snowflake from "node-snowflake.js"
export const createID = snowflake();
async function main(){
  const id0 = createID();
  const id1 = createID();
  const id2 = createID();
}
```

## 多进程使用, 使用环境变量配置 workerID, dataCenterID
```ts
import snowflake from "node-snowflake.js";
const workerId = parseInt(process.env.WORKER_ID || "0", 10)
const dataCenterId = parseInt(process.env.DATA_CENTER_ID || "0", 10)
export const createID = snowflake({ workerId, dataCenterId });
```

## Speed
受限于操作系统和nodejs性能, 无法做到最大速度 4096/ms 个
在 iMac 上平均速度为 1400/ms
运行测试的方式
```
yarn build;

yarn test-speed;
```

---
_Source: https://npm.io/package/node-snowflake.js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
