Skip to Content
URL Shortener (2)

Source: Jolli-sample-repos/url-shortener  Last Updated: 4/8/2026


URL Shortener

Node.js + Express API for shortening URLs with analytics, custom codes, and expiration.

System Flow

Request/response lifecycle showing how URLs flow from browser through validation, storage, and back.

File Structure

Project organization with backend TypeScript modules and vanilla JS frontend.

url-shortener/ ├── backend/src/ │ ├── index.ts # Express setup, /r/:code redirect handler │ ├── routes.ts # 6 API endpoints + OpenAPI comments │ ├── models.ts # TypeScript interfaces (5 types) │ ├── storage.ts # Map operations with dual indexes │ ├── generator.ts # nanoid 6-char codes, custom code validation │ ├── validator.ts # Zod schemas for create/update │ └── swagger.ts # OpenAPI configuration └── frontend/ ├── index.html # URL form, list, stats ├── js/app.js # API client, DOM manipulation └── css/style.css # Responsive layout

Core Features

What the URL shortener supports out of the box.

  • Auto-gen codes: nanoid 6-char alphanumeric (62^6 = 56B combinations)
  • Custom codes: 4-20 chars, uniqueness validation
  • Expiration: ISO 8601 datetime, returns 410 Gone
  • Analytics: Click tracking, last accessed timestamp
  • Deduplication: Same long URL returns existing short code