Skip to main content

API Reference

new URLShortener(baseDomain, store)

Creates a new instance of the URL shortener.

Parameters:

ParameterTypeRequiredDefaultDescription
baseDomainstring"https://sho.rt"Domain used for generated short URLs
storeStoreAdapternoneRedis-backed store (via RedisStore)

Returns:

  • A configured instance of URLShortener

shorten(longUrl, options?)

Generates a shortened version of a long URL.

Parameters:

ParameterTypeRequiredDescription
longUrlstringThe full URL to shorten
optionsobjectOptional settings (alias, expiresIn, override)
aliasstringOptional custom slug (e.g., launch)
expiresInstringExpiration duration like 1h, 30m, 7d
overridebooleanOverwrite an existing alias if one exists

Returns:

  • Promise<string> – The shortened URL (e.g., https://sho.rt/launch)

resolve(alias)

Resolves a short alias back to the original URL.

Parameters:

ParameterTypeRequiredDescription
aliasstringThe short code to resolve

Returns:

  • Promise<string | null> – Original URL, or null if not found or expired

🧱 StoreAdapter Interface

Any custom store implementation (such as RedisStore) must implement the following methods:

interface StoreAdapter {
get(alias: string): Promise<StoreEntry | null>;
set(alias: string, entry: StoreEntry, override?: boolean): Promise<void>;
delete(alias: string): Promise<void>;
has(alias: string): Promise<boolean>;
list(): Promise<Record<string, StoreEntry>>;
clearExpired(): Promise<void>;
}

Each StoreEntry looks like this:

interface StoreEntry {
url: string;
expiresAt?: number;
}

✅ Runtime Compatibility

EnvironmentStatus
Node.js✅ Yes
Deno✅ Yes
Bun✅ Yes

Note: This package is for backend use. You must proxy it through your own API if used with a frontend app.


🗃 Supported Store

StoreRuntimeNotes
RedisStore✅ Node-onlyRequires Redis and redis package