uniqid
Generates unique hexatridecimal IDs from the current time, process ID, and MAC address for Node.js and browsers.
Repository Health
Technical Analysis
uniqid is a lightweight JavaScript library that generates unique identifiers by combining the current timestamp, process ID, and network MAC address into a compact hexatridecimal (base-36) string. It has zero runtime dependencies and works across Node.js, browser bundlers (Webpack, Browserify, Vite), and directly via a UMD script tag from a CDN.
The library exposes three generation strategies with different uniqueness guarantees: a full 18-byte ID safe across multiple machines and processes, a 12-byte ID unique across processes on a single machine, and an 8-byte ID unique only within a single process. This lets consumers pick the cheapest option that satisfies their actual uniqueness requirements instead of always paying for the strongest guarantee.
What You Get
- Three ID generation tiers (
uniqid(),.process(),.time()) trading uniqueness scope for ID length - Optional prefix/suffix arguments on every generator function for namespacing IDs
- Zero runtime dependencies — the entire library is a single ~50-line index.js file
- A prebuilt UMD bundle for direct
<script>tag usage from a CDN, with automatic fallback to time-based IDs in bundler/browser contexts
Common Use Cases
- Generating request/correlation IDs for logging and tracing across a distributed Node.js service
- Creating temporary file or cache key names that must not collide across concurrent processes
- Assigning client-side element or session IDs in browser code via the UMD bundle, without a build step
- Producing short, sortable-by-time identifiers as a lighter alternative to UUIDs
Under The Hood
Architecture
uniqid ships as a single ~50-line CommonJS module with no internal layering — one file exports three functions (default, .process, .time) that share a private now() helper implementing a monotonic counter via a static property attached to the function itself. There is no dependency injection, no abstraction over the ID-generation strategy beyond the three exported entry points, and the only structural branching is a runtime check for __webpack_require__ that decides whether to pull in Node’s os module for MAC-address lookup. Because the whole surface area lives in one file with no internal seams, there is effectively nothing to break by changing the core abstraction — any change touches the entire module directly.
Tech Stack
The library is plain, dependency-free JavaScript (CommonJS module.exports) with zero runtime dependencies; its only devDependencies are webpack and webpack-cli, used solely to produce the prebuilt UMD bundle checked into UMD/uniqid.min.js for CDN/script-tag consumption. There is no TypeScript, no transpilation pipeline, and no bundler config beyond the single webpack.config.js for that UMD build. Deployment is a standard npm publish; the package declares no build framework, ORM, or database — it is a pure utility function.
Code Quality
No test files or test framework of any kind exist in the repository, and the .github/ directory contains only a FUNDING.yml — there is no CI workflow, linter configuration, or type checking. Error handling is implicit (no explicit validation of prefix/suffix argument types), naming is short and consistent (uniqid, .process, .time), and the monotonic-time helper relies on a mutable static property on the function object rather than a more conventional closure-scoped variable — a minor but real code smell for an otherwise minimal codebase.
API Design
The public API is intentionally small and easy to onboard: a single default export plus two named variants, each accepting the same optional prefix/suffix signature, requiring no configuration or setup step to start generating IDs. The three-tier design (full/process/time) communicates its uniqueness trade-off directly through naming, and the README documents exact expected output for each variant. The one friction point is implicit behavior — bundler/browser environments silently fall back to time-only uniqueness with no runtime warning, which a consumer could miss if they don’t read the docs closely.
Used by 3 apps in this directory
Bigcapital
Invoicing Finance
Self-hostable double-entry accounting platform with invoicing, inventory, multi-currency, and real-time financial reporting for small and medium businesses.
GrowthBook
Developer Tools · Analytics · Monitoring
Open source feature flags, A/B testing, and warehouse-native experimentation that queries your existing data infrastructure—no data movement required.
Webiny JS
Ecommerce · Blogging · CMS
Open-source, self-hosted CMS on AWS serverless — a TypeScript framework you extend with code, not a product you configure through a UI.