Using npm:
$ npm install fast-snowflake-idUsing yarn:
$ yarn add fast-snowflake-id- Get snowflake id as bigint
- Get snowflake id as buffer
Without any dependencies!
setup:
// CommonJS
const SnowflakeId = require('fast-snowflake-id').default;
// ES Module
import SnowflakeId from 'fast-snowflake-id';initialization:
// All properties are optional
const snowflakeId = new SnowflakeId({
epoch: 1288834974657 /* Twitter's snowflake id epoch */,
instanceId: SnowflakeId.getInstanceId(31, 31) /* Getting instanceId from datacenterId and workerId */,
overflowHandler: function () {
console.error('overflow!!!!');
return;
}
});printing snowflake id as bigint:
console.log(snowflakeId.getId());printing snowflake id as buffer:
console.log(snowflakeId.getBufferId());Contribution, issues and feature requests are welcome!
Feel free to check issues page.
