A modern, full-stack code snippet sharing platform built with React and Node.js. Share, store, and manage your code snippets with syntax highlighting, user authentication, and automatic expiration.
π Live Demo: TheCodeBin
- User Authentication: Secure signup/signin with JWT tokens
- Code Snippet Management: Create, view, edit, and delete code snippets
- Multi-language Support: Syntax highlighting for Python, JavaScript, Java, C++, and more
- Automatic Expiration: Set snippets to expire after 10m, 30m, 1h, 1d, 1w, or never
- Short URLs: Easy-to-share short IDs for each snippet
- Responsive Design: Modern UI built with React and TailwindCSS
- Real-time Feedback: Toast notifications for user actions
Screenshots will be added here once the application is deployed
codebin/
βββ backend/ # Node.js/Express API
β βββ src/
β β βββ controllers/ # Route handlers
β β βββ db/ # Database models and connection
β β βββ middleware/ # Custom middleware
β β βββ routes/ # API routes
β β βββ validations/ # Zod validation schemas
β β βββ server.js # Entry point
β βββ package.json
βββ frontend/ # React application
β βββ src/
β β βββ components/ # Reusable UI components
β β βββ pages/ # Page components
β β βββ store/ # Zustand state management
β β βββ lib/ # Utilities and configurations
β β βββ ui/ # UI component library
β βββ public/ # Static assets
β βββ package.json
βββ package.json # Root package.json
βββ README.md # This file
- React 19 - UI framework
- Vite - Build tool and development server
- TailwindCSS - Styling framework
- CodeMirror - Code editor with syntax highlighting
- React Router - Client-side routing
- Zustand - State management
- Axios - HTTP client
- React Hot Toast - Notifications
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database
- Mongoose - ODM for MongoDB
- JWT - Authentication tokens
- bcrypt - Password hashing
- Zod - Input validation
- CORS - Cross-origin resource sharing
Before running this project, make sure you have:
- Node.js (v18 or higher)
- npm or yarn
- MongoDB (local installation or MongoDB Atlas)
-
Clone and install dependencies
git clone https://github.com/kartik-py12/codebin.git cd codebin npm install cd backend && npm install cd ../frontend && npm install && cd ..
-
Set up environment
cd backend cp .env.example .env # Create this if needed # Edit .env with your MongoDB URI and JWT secret
-
Start development servers
# Terminal 1 - Backend cd backend && npx nodemon src/server.js # Terminal 2 - Frontend cd frontend && npm run dev
-
Open your browser
- Frontend: http://localhost:5173
- Backend API: http://localhost:3000
-
Clone the repository
git clone https://github.com/kartik-py12/codebin.git cd codebin -
Install root dependencies
npm install
-
Install backend dependencies
cd backend npm install -
Install frontend dependencies
cd ../frontend npm install
-
Create environment file for backend
cd backend touch .env -
Add the following environment variables to
backend/.env:MONGO_URI=mongodb://localhost:27017/codebin JWT_SECRET=your_jwt_secret_key_here NODE_ENV=development
For MongoDB Atlas:
MONGO_URI=mongodb+srv://username:password@cluster.mongodb.net/codebin JWT_SECRET=your_jwt_secret_key_here NODE_ENV=development
-
Start the backend server
cd backend npx nodemon src/server.jsBackend will run on
http://localhost:3000 -
Start the frontend development server
cd frontend npm run devFrontend will run on
http://localhost:5173
-
Build the frontend
cd frontend npm run build -
Start the backend server
cd backend node src/server.js
Create a new user account.
{
"username": "string (3-64 chars)",
"email": "string (valid email)",
"password": "string (6-64 chars, must contain uppercase, number, special char)"
}Sign in with existing credentials.
{
"username": "string",
"password": "string"
}Sign out the current user (requires authentication).
Get current user information (requires authentication).
Create a new code snippet (requires authentication).
{
"title": "string (max 100 chars)",
"content": "string (required)",
"language": "string (default: plaintext)",
"expiryTime": "10m|30m|1h|1d|1w|never (optional)"
}Get a specific snippet by its short ID.
Get all snippets for the authenticated user (requires authentication).
Update an existing snippet (requires authentication). At least one field must be provided.
{
"title": "string (max 100 chars, optional)",
"content": "string (optional)",
"language": "string (optional)",
"expiryTime": "10m|30m|1h|1d|1w|never (optional)"
}Delete a snippet (requires authentication).
- Sign Up/Sign In: Create an account or sign in with existing credentials
- Create Snippet: Click "New Snippet" to create a code snippet
- Choose Language: Select the programming language for syntax highlighting
- Set Expiration: Choose when the snippet should expire
- Share: Use the generated short URL to share your snippet
- Manage: View, edit, or delete your snippets from your profile
-
Backend fails to start
- Ensure MongoDB is running
- Check that the .env file is properly configured
- Verify all dependencies are installed
-
Frontend can't connect to backend
- Ensure backend is running on port 3000
- Check CORS configuration in backend/src/server.js
- Verify frontend is running on port 5173
-
Build fails
- Clear node_modules and reinstall dependencies
- Check Node.js version (requires v18+)
-
Database connection issues
- Verify MongoDB connection string in .env
- Check MongoDB service is running
- For MongoDB Atlas, verify network access and credentials
- Use
npx nodemon src/server.jsfor backend hot-reload during development - Frontend automatically reloads when files change
- Check browser console for client-side errors
- Check terminal output for server-side errors
- JavaScript
- Python
- Java
- C++
- Plain Text
- And more...
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is open source and available under the MIT License.
- Server may take a few seconds to wake up on first load (hosting limitation)
- CORS is configured for localhost:5173 in development
If you encounter any issues or have questions, please:
- Check the existing Issues
- Create a new issue if your problem isn't already reported
- Include detailed information about your environment and the steps to reproduce
- Built with modern web technologies
- Inspired by Pastebin and similar code sharing platforms
- Thanks to all contributors and the open-source community
Happy Coding! π