Skip to main content
shrtnr hero shrtnr is a minimal link shortener that makes sharing URLs simple and beautiful. Paste any long URL and get an instant short link. Create an account to unlock custom slugs, click tracking, and a dashboard to manage all your links.

Quickstart Guide

Get started in 2 minutes - from signup to your first short link

Custom Slugs

Create branded short links with memorable custom URLs

Analytics & Tracking

Monitor click counts and understand link performance

Dashboard

Manage, edit, and organize all your short links in one place

Why shrtnr?

Long URLs are hard to share, break in messages, and look unprofessional. shrtnr solves this with:
  • Instant short links - Generate an 8-character short code automatically with nanoid
  • Custom slugs - Choose your own memorable URLs (1-20 characters: letters, numbers, _ and -)
  • Click tracking - Every click is recorded with IP, user agent, and referrer data
  • Link expiration - Set expiry dates from 1-30 days (default: 7 days)
  • Redis caching - Lightning-fast redirects powered by Upstash Redis
  • Dashboard - View, edit, and delete all your links from one interface
No account required to create links! Sign up only when you want custom slugs, analytics, or a dashboard.

How it works

1

Paste your URL

Drop any long URL into the input field on the home page. No validation until you submit.
2

Get a short link

Click “Shorten” and we generate an 8-character code using nanoid. If you’re signed in, you can use a custom slug instead.
3

Share anywhere

Your short link is automatically copied to your clipboard. Share it in messages, social media, or print materials.
4

Track performance

When someone clicks your link, we redirect them instantly (HTTP 307) and record the click. View stats in your dashboard.

Key features

Automatic code generation

Every link gets a unique 8-character short code generated by the nanoid library:
import { nanoid } from 'nanoid';

const SHORT_CODE_LENGTH = 8;
const shortCode = nanoid(SHORT_CODE_LENGTH);
// Example: 'V1StGXR8'
Authenticated users can choose their own slugs following a simple pattern:
const SLUG_REGEX = /^[a-zA-Z0-9_-]{1,20}$/;

// Valid slugs:
// - "my-link" ✓
// - "2024_campaign" ✓
// - "product-launch" ✓
// 
// Invalid slugs:
// - "my link" ✗ (spaces not allowed)
// - "a" repeated 21 times ✗ (max 20 chars)
All links expire within 1-30 days (default: 7). The expiration is enforced both in the database and Redis:
const DEFAULT_EXPIRY_DAYS = 7;
const MAX_EXPIRY_DAYS = 30;

const expiresAt = new Date(Date.now() + days * 24 * 60 * 60 * 1000);
const ttlSeconds = Math.floor((expiresAt.getTime() - Date.now()) / 1000);

// Set in Redis with expiration
await redis.set(`short:${shortCode}`, originalUrl, { ex: ttlSeconds });

Redis-powered redirects

Every redirect checks Redis first for sub-millisecond response times:
// Check Redis cache first
const cached = await redis.get<string>(`short:${shortCode}`);
if (cached) return cached;

// Fall back to database if cache miss
const result = await db`
  SELECT original_url FROM urls
  WHERE short_code = ${shortCode}
    AND (expires_at IS NULL OR expires_at > NOW())
  LIMIT 1
`;
Links that have expired return a 404 error and will not redirect.

Click tracking

Every click increments a counter and logs detailed analytics:
// Increment click count
await db`UPDATE urls SET clicks = clicks + 1 WHERE short_code = ${shortCode}`;

// Log click event with metadata
await db`
  INSERT INTO clicks (short_code, ip_address, user_agent, referrer)
  VALUES (${shortCode}, ${ip}, ${userAgent}, ${referrer})
`;

Technology stack

shrtnr is built with modern web technologies:
  • Next.js 16 - React framework with App Router
  • Neon Database - Serverless Postgres for link storage
  • Upstash Redis - Edge caching for instant redirects
  • NextAuth.js 5 - Authentication with credentials provider
  • Tailwind CSS - Utility-first styling
  • TypeScript - Type-safe development

API endpoints

POST /api/shorten

Create a new short link with optional custom slug and expiration

GET /api/links

List all links for the authenticated user

PATCH /api/links/[id]

Update a link’s slug or expiration date

DELETE /api/links/[id]

Delete a short link and clear its cache

What’s next?

Create your first link

Follow the quickstart to create an account and shorten your first URL

Learn about features

Explore custom slugs, analytics, and dashboard features

Build docs developers (and LLMs) love