Generate short URL-safe IDs for database records in a Node.js app instead of long UUIDs.
Create unique IDs in browser-side JavaScript without any server round trip.
Customize the character set used for IDs to meet specific URL or system encoding requirements.
The author recommends Nano ID for new projects due to architectural safety concerns with shortid.
Shortid is a JavaScript library that generates short, random-looking IDs suitable for use in URLs, database record keys, and anywhere else you need a compact unique identifier. A typical output looks something like PPBqWA9, using letters, numbers, hyphens, and underscores by default so the result is safe to paste directly into a web address without percent-encoding. The README opens with a deprecation notice. The author now recommends a different library called Nano ID instead, citing architectural safety concerns. Shortid is still widely used in older projects and the code remains available, but new projects are encouraged to look elsewhere. For existing users, the library works by calling shortid.generate() to get a new ID. The IDs are non-sequential, meaning they do not count up in order, so someone looking at a series of them cannot easily guess other valid IDs. The library also works across multiple server processes running in parallel, as long as each process is assigned a different worker number between 0 and 16. A seed value can also be set to make the internal random number generator harder to predict, though the library explicitly notes it does not produce cryptographically secure IDs and should not be used where guessability is a strong security requirement. The character set used for IDs can be customized. You provide any 64 unique characters and the library uses those instead of the default alphanumeric-plus-punctuation set. An isValid function checks whether a given string matches the format that shortid would produce. The library runs in Node.js and in browsers. It was originally built for a 2011 hackathon project and went on to be adopted by many open-source packages, several of which are listed in the README.
← dylang on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.