{"id":16216013,"url":"https://github.com/tangledbytes/nodejs-snowflake","last_synced_at":"2025-05-07T13:01:38.990Z","repository":{"id":36202922,"uuid":"222195883","full_name":"tangledbytes/nodejs-snowflake","owner":"tangledbytes","description":"Generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)","archived":false,"fork":false,"pushed_at":"2024-02-26T16:39:27.000Z","size":253,"stargazers_count":186,"open_issues_count":3,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-19T10:55:18.880Z","etag":null,"topics":["distributed-systems","hacktoberfest","nodejs","nodejs-snowflake","rust","snowflake","twitter","typescript","wasm","webassembly"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/nodejs-snowflake","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tangledbytes.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-11-17T04:16:15.000Z","updated_at":"2025-04-18T04:01:24.000Z","dependencies_parsed_at":"2024-06-18T14:28:06.784Z","dependency_job_id":"6040cb8e-386b-4d4f-8193-da9c2fd57f6c","html_url":"https://github.com/tangledbytes/nodejs-snowflake","commit_stats":null,"previous_names":["tangledbytes/nodejs-snowflake","utkarsh-pro/nodejs-snowflake"],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledbytes%2Fnodejs-snowflake","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledbytes%2Fnodejs-snowflake/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledbytes%2Fnodejs-snowflake/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tangledbytes%2Fnodejs-snowflake/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tangledbytes","download_url":"https://codeload.github.com/tangledbytes/nodejs-snowflake/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252883219,"owners_count":21819157,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["distributed-systems","hacktoberfest","nodejs","nodejs-snowflake","rust","snowflake","twitter","typescript","wasm","webassembly"],"created_at":"2024-10-10T11:17:42.884Z","updated_at":"2025-05-07T13:01:38.969Z","avatar_url":"https://github.com/tangledbytes.png","language":"Rust","readme":"# nodejs-snowflake\n\n[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://github.com/tangledbytes/nodejs-snowflake/graphs/commit-activity)\n[![GitHub issues](https://img.shields.io/github/issues/tangledbytes/nodejs-snowflake.svg)](https://github.com/tangledbytes/nodejs-snowflake/issues/)\n![License](https://img.shields.io/npm/l/nodejs-snowflake)\n![Top Language](https://img.shields.io/github/languages/top/tangledbytes/nodejs-snowflake)\n![Version](https://img.shields.io/npm/v/nodejs-snowflake)\n![GitHub Workflow Status](https://img.shields.io/github/actions/workflow/status/tangledbytes/nodejs-snowflake/release.yml?branch=master)\n\nnodejs-snowflake is a fast and reliable way to generate time sortable 64 bit ids written for distributed systems.  \nThe main ID generation function is written in Rust which interoperates with NodeJS via WASM, this makes the process of ID generation extremely fast.\n\n\u003e ⚠️ Version 2 Alert! Version 2 of `nodejs-snowflake` has a lot of breaking changes and is a complete rewrite. Consider going through entire doc to understand the migration path. Checkout [Version 2 PR Notes](https://github.com/tangledbytes/nodejs-snowflake/pull/14) for details.\n\n## How to install\n\n```\nnpm install nodejs-snowflake --save\nyarn add nodejs-snowflake\n```\n\n## Usage\n\n### Generate ID\n\n```javascript\nconst { Snowflake } = require('nodejs-snowflake');\n\nconst uid = new Snowflake(config);\n\nuid.getUniqueID(); // A 64 bit id is returned\n\n```\n\n#### Configuration\nUniqueID constructor takes in the following configuration\n\n```javascript\n{\n    custom_epoch: number, // Defaults to Date.now(). This is UNIX timestamp in ms\n    instance_id: number // A value ranging between 0 - 4095. If not provided then a random value will be used\n}\n```\n\n### Get ID corresponding to a Timestamp\nThis can be extremely helpful in writing database queries where the requirement could be to get entries created after a certain timestamp.\n\n```javascript\n...\n\nconst id = uid.idFromTimestamp(Date.now()); // Here id will always be BigInt\n\nconsole.log(id); // A 64 bit id is returned corresponding to the timestamp given\n\n```\n\n### Get timestamp from the ID\nGet the timestamp of creation of the ID can be extracted by using this method. This method will work even if this instance or machine wasn't actually used to generate this id.\n\n```javascript\n...\n\n// Pass the custom epoch that was used to generate this ID\nconst ts = Snowflake.timestampFromID(id, uid.customEpoch());\n\nconsole.log(ts) // Timestamp of creation of the id\n\n```\n\n### Get machine id from the ID\nGet the machine id of the machine on which the token was generated. This method will work even if this instance or machine wasn't actually used to generate this id.\n\n```javascript\n...\n\nconst mid = Snowflake.instanceIDFromID(id);\n\nconsole.log(mid); // 2345 -\u003e This is the 12 bit long machine id where this token was generated\n\n```\n\n### Get the current machine id\nThis solely exits to find the machine id of current machine in case the user didn't provided as machine id and relied on the randomly generated value.\n\n```javascript\n...\n\nuid.instanceID(); // The instance id of the current instance, set either by user or randomly generated\n\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftangledbytes%2Fnodejs-snowflake","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftangledbytes%2Fnodejs-snowflake","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftangledbytes%2Fnodejs-snowflake/lists"}