A clean URL Shortener backend built with NestJS, TypeScript, PostgreSQL, Prisma ORM, and Redis.
- Create short URLs from long URLs
- Optional custom alias support
- Redirect short URL to original URL
- Optional expiry date for links
- Basic click analytics
- Click count per day
- Redis-based URL caching
- Basic IP-based rate limiting
- Health check endpoint
- Node.js
- NestJS
- TypeScript
- PostgreSQL
- Prisma ORM
- Redis
src/urls- URL shortener featuresrc/prisma- Prisma database integrationsrc/redis- Redis caching and rate limitingsrc/common- shared filters & Global Exception handlingsrc/health- health endpoint
Create a short URL.
Request body:
{
"originalUrl": "https://example.com",
"customAlias": "myalias",
"expiresAt": "2026-05-30T10:00:00.000Z"
}Redirect to the original URL.
Get analytics for a short URL.
- Example response:
{
"shortCode": "myalias",
"originalUrl": "https://example.com",
"totalClicks": 12,
"clicksPerDay": [
{
"date": "2026-05-22",
"count": 12
}
]
}Check if the service is running.
- Install dependencies:
npm install
- Configure .env and update the .env.example
- Start PostgreSQL and Redis
- Generate Prisma client:
npx prisma generate
- Run migrations:
npx prisma migrate dev --name init
- Start the server:
npm run start:dev