I published my first npm package: `short-id-lite` 🎉
Source: Dev.to
A tiny, secure short ID generator for Node.js — feedback welcome
Publishing your first npm package is oddly intimidating. You keep asking yourself:
- “Is this useful enough?”
- “Am I reinventing the wheel?”
- “Will anyone actually use this?”
Last week I decided to stop overthinking and ship something small, focused, and honest: short-id-lite.
- GitHub repo: https://github.com/BasharVI/short-id-lite
- npm package: https://www.npmjs.com/package/short-id-lite
Why short IDs are useful
In almost every backend project you eventually need short IDs for things like:
- Invite codes
- Public‑facing references
- Temporary tokens
- Human‑friendly identifiers
These are not UUIDs or database IDs—just short, random, URL‑safe strings.
Existing solutions and their trade‑offs
| Solution | Drawbacks |
|---|---|
| UUIDs | Too long, not human‑friendly, overkill for many use cases |
Math.random‑based helpers | Easy to write but not safe; collision risk and predictability issues |
| Fully featured libraries (e.g., nanoid) | Excellent, but often provide more options, more surface area, and more code to audit than needed for very small use cases |
What I wanted
“Give me a short, safe ID. No config. No decisions.”
short-id-lite: design goals
- Extremely small – only a few lines of code.
- Dependency‑free – no external packages.
- Crypto‑safe – uses Node.js
crypto.randomBytes. - Boring in the best way – minimal API, no surprises.
- Easy to audit – straightforward implementation.
- Stable for years – no hidden moving parts.
This package is not meant to replace nanoid. It’s intended to cover the 80 % case with 10 % of the complexity.
Features
- Generates short, URL‑safe IDs.
- Uses Node.js crypto (
crypto.randomBytes). - Exposes a single function.
- No configuration objects.
- No mutable global state.
- No browser support (Node.js only).
- No magic.
Installation
npm install short-id-lite
Usage
import { shortId } from "short-id-lite";
shortId(); // e.g. "aZ3F9q"
shortId(10); // e.g. "Qm9KfP2aXz"
The optional numeric argument specifies the desired length of the generated ID.