{"id":10855,"library":"eventid","title":"Globally Unique, Monotonically Increasing Event IDs","description":"eventid is a JavaScript/TypeScript utility for generating unique event identifiers that are globally unique across a network of services and monotonically increasing locally on each machine. Currently at stable version 2.0.1, the library typically receives updates for Node.js compatibility and internal dependency management, with new major versions signifying breaking changes like increased minimum Node.js requirements. It provides a robust alternative to standard JavaScript timestamps, which often lack the necessary millisecond resolution for accurately ordering rapidly occurring events within distributed systems. Its core differentiation lies in producing lexicographically comparable IDs that maintain local monotonicity while guaranteeing global uniqueness, thereby facilitating event ordering across diverse services without relying on imprecise timestamp comparisons.","status":"active","version":"2.0.1","language":"javascript","source_language":"en","source_url":"https://github.com/google/eventid-js","tags":["javascript","uid","typescript"],"install":[{"cmd":"npm install eventid","lang":"bash","label":"npm"},{"cmd":"yarn add eventid","lang":"bash","label":"yarn"},{"cmd":"pnpm add eventid","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Used internally for generating the globally unique component of the event ID.","package":"uuid","optional":false}],"imports":[{"note":"The EventId class is exported as the default export of the module for both ESM and CommonJS. Named imports will fail.","wrong":"import { EventId } from 'eventid';","symbol":"EventId","correct":"import EventId from 'eventid';"},{"note":"For CommonJS, the class constructor is directly exported, not as a property of an object.","wrong":"const { EventId } = require('eventid');","symbol":"EventId (CommonJS)","correct":"const EventId = require('eventid');"},{"note":"Since 'EventId' is the default export (a class), its type can be imported using 'import type EventId from 'eventid';' or by inferring the instance type.","wrong":"import { EventId } from 'eventid';","symbol":"EventId type","correct":"import type EventId from 'eventid';\n// or\ntype MyEventId = InstanceType<typeof EventId>;"}],"quickstart":{"code":"import EventId from 'eventid';\n\n// Instantiate a generator. A single instance is sufficient for an application.\nconst eventIdGenerator = new EventId();\n\n// Generate a globally unique identifier.\nconst id1: string = eventIdGenerator.new(); \nconsole.log(`Generated ID 1: ${id1}`);\n\n// Subsequent calls from the same generator instance will produce\n// monotonically increasing local IDs.\nconst id2: string = eventIdGenerator.new();\nconsole.log(`Generated ID 2: ${id2}`);\n\n// Verify monotonic increase locally\nif (id1 < id2) {\n  console.log('id1 is lexicographically smaller than id2, as expected.');\n} else {\n  console.error('ID generation is not monotonically increasing locally!');\n}\n\n// Another instance (e.g., in a different service or process) will use\n// a different base GUID, ensuring global uniqueness.\nconst anotherGenerator = new EventId();\nconst id3: string = anotherGenerator.new();\nconsole.log(`Generated ID 3 (from another generator): ${id3}`);\n\n// Example of how they compare - generally, IDs from different generators\n// are not necessarily ordered relative to each other.\n// But IDs from the *same* generator are strictly ordered.\n","lang":"typescript","description":"Demonstrates instantiation of EventId, generation of unique IDs, and verification of their local monotonic increase. It highlights how different instances ensure global uniqueness while individual instances maintain local order."},"warnings":[{"fix":"Upgrade your Node.js environment to version 10 or greater. For older Node.js environments, you must use a version of `eventid` prior to 2.0.0 (e.g., `npm install eventid@^1.0.0`).","message":"Version 2.0.0 and above explicitly require Node.js 10 or higher. Previous versions of Node.js are no longer supported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your Node.js environment is at least version 8.x for `eventid` v1.x, or upgrade to Node.js 10+ for `eventid` v2.x.","message":"Version 1.0.0 dropped support for Node.js versions 4.x, 6.x, and 9.x, which had reached or were nearing End-Of-Life (EOL).","severity":"breaking","affected_versions":">=1.0.0 <2.0.0"},{"fix":"Be aware that support and maintenance are community-driven and subject to the availability of contributors. Do not assume enterprise-level support or SLAs.","message":"This package is not an official Google product. While developed and open-sourced by Google employees, it does not carry official Google product support or guarantees.","severity":"gotcha","affected_versions":"*"},{"fix":"If `d64` is required by your application, install it as a direct dependency (`npm install d64`). Do not rely on transitive dependencies.","message":"The `d64` dependency was removed in v2.0.1. While this was a dependency fix, users who might have implicitly relied on `d64` being present in their node_modules (which is not recommended practice) might find it missing.","severity":"gotcha","affected_versions":">=2.0.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Use the correct default import syntax: `import EventId from 'eventid';` for ESM/TypeScript or `const EventId = require('eventid');` for CommonJS.","cause":"Incorrectly importing EventId using named import syntax (e.g., `import { EventId } from 'eventid';`) when it is exported as a default.","error":"TypeError: EventId is not a constructor"},{"fix":"In an ESM context, use `import EventId from 'eventid';`. If you must use `require`, ensure your project is configured for CommonJS or use a build tool to transpile.","cause":"Attempting to use `require('eventid')` in an ECMAScript Module (ESM) context in Node.js without proper Babel/Webpack configuration.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ...eventid/index.js from ... not supported."},{"fix":"Ensure `import EventId from 'eventid';` or `const EventId = require('eventid');` is present and correctly positioned in your module before `new EventId()` is called.","cause":"The `EventId` class has not been imported or required correctly, or an attempt to use it was made before it was in scope.","error":"ReferenceError: EventId is not defined"}],"ecosystem":"npm"}