WePaste is a full-stack MERN application that combines pastebin functionality with file sharing capabilities. Users can upload unlimited text, multiple images, and multiple files, all accessible through a randomly generated key. All content automatically expires after 2 hours.
Experience WePaste in production: https://wepaste.onrender.com
- π Unlimited Text Upload - Share any amount of text content
- πΌοΈ Multiple Images - Upload up to 20 images (10MB each)
- π Multiple Files - Upload up to 20 files (10MB each)
- π Random Key Access - Secure, randomly generated keys for content access
- β° Auto-Expiration - Content automatically expires after 2 hours
- π Fast & Secure - Built with MongoDB GridFS for efficient file storage
- π¨ Modern UI - Beautiful, responsive React frontend with Tailwind CSS
- Node.js - Runtime environment
- Express - Web framework
- MongoDB Atlas - Cloud database
- Mongoose - MongoDB ODM
- GridFS - File storage system
- Multer - File upload middleware
- nanoid - Random key generator
- Helmet - Security headers
- CORS - Cross-origin resource sharing
- express-rate-limit - Rate limiting
- React 18 - UI library
- React Router - Client-side routing
- Axios - HTTP client
- Tailwind CSS - Utility-first CSS framework
Before you begin, ensure you have:
- Node.js (v14 or higher) installed
- npm or yarn package manager
- MongoDB Atlas account (free tier works)
- Git installed
git clone <repository-url>
cd WePaste# Navigate to backend directory
cd backend
# Install dependencies
npm install
# Create .env file from example
cp env.example.txt .env
# Edit .env file with your MongoDB Atlas connection string
# Replace username, password, and cluster URLBackend .env file structure:
PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb+srv://username:password@cluster.mongodb.net/wepaste?retryWrites=true&w=majority
GRIDFS_BUCKET_NAME=uploads
FRONTEND_URL=http://localhost:3000# Navigate to frontend directory (from project root)
cd frontend
# Install dependencies
npm install
# Create .env file (optional - defaults to http://localhost:5000/api)
# Copy env.example.txt to .env if you want to customize API URLFrontend .env file (optional):
REACT_APP_API_URL=http://localhost:5000/api# From backend directory
npm run dev # Development mode with auto-reload
# OR
npm start # Production modeBackend will run on http://localhost:5000
# From frontend directory (in a new terminal)
npm startFrontend will run on http://localhost:3000
Open http://localhost:3000 in your browser to view the application.
WePaste/
βββ backend/ # Backend API
β βββ config/ # Configuration files
β β βββ database.js # MongoDB & GridFS setup
β βββ controllers/ # Route controllers
β β βββ contentController.js
β βββ middleware/ # Express middleware
β β βββ errorHandler.js
β β βββ upload.js # Multer configuration
β βββ models/ # Mongoose models
β β βββ Text.js
β β βββ ImageMeta.js
β β βββ FileMeta.js
β β βββ RandomKeys.js
β βββ routes/ # API routes
β β βββ contentRoutes.js
β βββ utils/ # Utility functions
β β βββ gridfs.js # GridFS helpers
β β βββ keyGenerator.js # nanoid wrapper
β β βββ fileValidator.js
β βββ .env # Environment variables (create from env.example.txt)
β βββ package.json
β βββ server.js # Express app entry point
β βββ README.md
β
βββ frontend/ # React frontend
β βββ public/ # Static files
β βββ src/
β β βββ components/ # React components
β β β βββ UploadForm.jsx
β β β βββ PreviewImage.jsx
β β β βββ FileDownload.jsx
β β βββ pages/ # Page components
β β β βββ UploadPage.jsx
β β β βββ ViewContentPage.jsx
β β βββ utils/ # Utilities
β β β βββ api.js # API helper functions
β β βββ App.js # Main App component
β β βββ App.css
β β βββ index.js # React entry point
β β βββ index.css
β βββ package.json
β βββ .env # Frontend environment variables (optional)
β
βββ postman_collection.json # Postman API collection
βββ README.md # This file
POST /api/createContent
Upload text, images, and/or files.
Request:
- Content-Type:
multipart/form-data - Body:
text(string, optional)images(file[], optional, max 20, 10MB each)files(file[], optional, max 20, 10MB each)
Response:
{
"success": true,
"data": {
"randomKey": "abc123xyz",
"expireIn": "2 hours"
}
}GET /api/readContent/:randomKey
Retrieve content by random key.
Response:
{
"success": true,
"data": {
"text": "Your text content",
"images": [
{
"id": "fileId",
"name": "image.jpg",
"type": "image/jpeg",
"url": "/api/download/fileId"
}
],
"files": [
{
"id": "fileId",
"name": "document.pdf",
"type": "application/pdf",
"url": "/api/download/fileId"
}
]
}
}GET /api/download/:fileId
Download a file from GridFS.
DELETE /api/delete/:randomKey
Delete content by random key (only valid within 2 hours).
Response:
{
"success": true,
"message": "Content deleted successfully"
}GET /health
Server health status.
Stores text content with expiration time.
Stores metadata for uploaded images (references GridFS files).
Stores metadata for uploaded files (references GridFS files).
Maps random keys to content items (text, images, files).
All collections use MongoDB TTL indexes for automatic expiration after 2 hours.
- Helmet.js - Security headers
- CORS - Configured cross-origin resource sharing
- Rate Limiting - 100 requests per 15 minutes (general), 50 per hour (content creation)
- File Validation - Size limits (10MB), type validation
- Executable Blocking - Blocks executable files for security
- Navigate to the home page (
/) - Enter text in the textarea (optional)
- Select images using the image file input (optional)
- Select files using the file file input (optional)
- Click "Upload Content"
- Copy the generated random key or click "Open Content"
- Navigate to
/view/:keywhere:keyis your random key - View text, images, and download files
- Use "Copy URL" to share the content link
- Use "Delete" to remove content (only within 2 hours)
Import the postman_collection.json file into Postman to test all API endpoints.
cd frontend
npm run buildThe production build will be in the frontend/build directory.
- Set
NODE_ENV=productionin.env - Update MongoDB URI for production
- Configure CORS for production frontend URL
- Use process manager like PM2:
npm install -g pm2
pm2 start backend/server.js --name wepaste-api- Backend: Deploy to Heroku, AWS, DigitalOcean, etc.
- Frontend: Deploy to Vercel, Netlify, AWS S3 + CloudFront, etc.
- Database: MongoDB Atlas (already cloud-based)
- Environment Variables: Set production values in hosting platform
- MongoDB Connection Error: Check your MongoDB Atlas connection string in
.env - GridFS Error: Ensure MongoDB connection is established before accessing GridFS
- Port Already in Use: Change
PORTin.envfile
- API Connection Error: Check
REACT_APP_API_URLin frontend.env - CORS Error: Ensure backend CORS is configured for frontend URL
- Build Errors: Clear
node_modulesand reinstall dependencies
Contributions are welcome! Please feel free to submit a Pull Request.
ISC
Built with β€οΈ using the MERN stack
- MongoDB Atlas for cloud database hosting
- nanoid for random key generation
- React team for the amazing framework
Note: All content expires after 2 hours. Make sure to download or save important content before expiration.