This is a Pastebin-like web application built using Next.js (App Router).
It allows users to create text pastes and share a unique link to view them.
Each paste can optionally expire after a given time (TTL) or after a maximum number of views.
Once a constraint is triggered, the paste becomes unavailable.
The project is designed to work correctly in serverless environments and is suitable for automated evaluation.
- Create a text paste
- Receive a shareable URL
- View pastes via a public link
- Optional time-based expiry (TTL)
- Optional view-count limit
- Safe content rendering (prevents script execution)
- Persistent storage across requests
- Next.js (App Router)
- Node.js
- Upstash Redis (persistence layer)
First, install the dependencies:
npm install
Environment Setup
Create a .env.local file in the project root:
env
UPSTASH_REDIS_REST_URL=your_upstash_redis_url
UPSTASH_REDIS_REST_TOKEN=your_upstash_redis_token
NEXT_PUBLIC_BASE_URL=http://localhost:3000
Run the Development Server
npm run dev
Open your browser and visit: http://localhost:3000app/
├── page.js # Homepage (create paste UI)
├── p/
│ └── [id]/
│ └── page.js # View paste page (HTML)
├── api/
│ └── pastes/
│ ├── route.js # Create paste API
│ └── [id]/
│ └── route.js # Fetch paste API
├── lib/
│ └── redis.js # Redis client- This project uses Upstash Redis for persistence.
- Pastes are stored as Redis hashes.
- Atomic Redis operations are used for view counting. -Data persists across serverless requests.
- Redis key versioning is used to avoid schema conflicts.
- All business logic (validation, TTL checks, view limits) is handled in API routes
- UI pages never access Redis directly
- Deterministic time support is included for automated testing
- Paste content is rendered safely to prevent XSS vulnerabilities
To learn more about Next.js, take a look at the following resources:
- Next.js Documentation
The easiest way to deploy this Next.js app is to use the Vercel Platform.
For more details, see the Next.js deployment documentation.