A modern web application for sharing text snippets with customizable expiration options. Built with Next.js, TypeScript, and MongoDB.
- Text Sharing: Share text content through unique, shareable links
- Expiration by Views: Set links to expire after a specific number of views
- Expiration by Time: Set links to expire after a certain number of hours
- Auto-deletion: Expired texts are automatically removed from the database
- View Tracking: Real-time tracking of how many times a link has been viewed
- Copy to Clipboard: One-click link copying functionality
- Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
- Server-Side Rendering: Built with Next.js 14 App Router
- TypeScript: Full type safety across the application
- MongoDB Integration: Efficient data storage with Mongoose ODM
- RESTful API: Clean API endpoints for creating and retrieving texts
- Error Handling: Comprehensive error handling for expired/missing content
- Modern UI: Clean, student-friendly interface with emojis and intuitive design
- User visits the home page
- Pastes or types text into the input field
- Selects expiration type:
- By Views: Link expires after X number of views
- By Time: Link expires after X hours
- Clicks "Generate Link" button
- Receives a unique shareable URL
- Copies and shares the link with others
- Recipient clicks on the shared link
- System checks if the text is still valid:
- Checks if expired by time
- Checks if maximum views reached
- If valid:
- Displays the text content
- Increments view counter
- Shows remaining views (if applicable)
- If expired:
- Shows "Text Not Available" error
- Automatically deletes the text from database
[User Input] → [API Route] → [MongoDB] → [Generate ID] → [Return Link]
↓
[Store Document with:
- text content
- expiration type
- max views / expiry time
- current view count]
[View Request] → [API Route] → [MongoDB Lookup] → [Check Expiration]
↓
[Increment Views]
↓
[Return Content or Error]
- Node.js 18+ installed
- MongoDB Atlas account (free tier) OR local MongoDB installation
- Git installed
git clone https://github.com/yourusername/pastebin.git
cd pastebinnpm installCreate a .env.local file in the root directory:
# For MongoDB Atlas
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/pastebin
Replace `username`, `password`, and `cluster` with your actual MongoDB credentials.
### Step 5: Create Required Files
Ensure you have `global.d.ts` in the root:
```typescript
declare global {
var mongoose: {
conn: any;
promise: any;
};
}
export {};npm run devOpen http://localhost:3000 in your browser.
-
Build the Docker image:
docker build -t pastebin . -
Run the container:
docker run -p 3000:3000 -e MONGODB_URI="your_connection_string" pastebin
- Frontend: Next.js 14, React 18, TypeScript
- Styling: Tailwind CSS
- Backend: Next.js API Routes
- Database: MongoDB
