A full-stack file sharing application built with React (frontend) and Node.js/Express (backend) that allows users to upload files and share them via unique download links.
- File Upload: Upload any file type through a simple drag-and-drop interface
- Unique Download Links: Each uploaded file gets a unique URL for sharing
- One-Click Copy: Copy the download link to clipboard with a single click
- Direct Download: Open files directly in browser or download them
- MongoDB Storage: File metadata stored in MongoDB with file paths
- Responsive UI: Clean and modern React frontend
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - Database for file metadata
- Mongoose - MongoDB object modeling
- Multer - File upload middleware
- CORS - Cross-origin resource sharing
- React 19 - Frontend framework
- Vite - Build tool and development server
- ESLint - Code linting
file-sharing/
├── backend/
│ ├── controller/
│ │ └── uploadController.js # File upload/download logic
│ ├── database/
│ │ └── db.js # MongoDB connection
│ ├── middleware/
│ │ └── upload.js # Multer configuration
│ ├── model/
│ │ └── fileModel.js # File schema
│ ├── routes/
│ │ └── api.js # API routes
│ └── index.js # Server entry point
├── frontend/
│ ├── src/
│ │ ├── App.jsx # Main React component
│ │ ├── service/
│ │ │ └── api.js # API service functions
│ │ └── ...
│ └── ...
├── fileFolder/ # Uploaded files storage
└── package.json
- Node.js (v14 or higher)
- MongoDB (local or cloud instance)
- npm or yarn
-
Clone the repository
git clone <repository-url> cd file-sharing
-
Install dependencies
# Install root dependencies npm install # Install frontend dependencies cd frontend npm install cd ..
-
Environment Configuration
Create a
.envfile in the root directory:PORT=8000 BACKEND_URL=http://localhost:8000 MONGODB_URI=mongodb://localhost:27017/filesharing
Create a
.envfile in the frontend directory:VITE_BACKEND_URL=http://localhost:8000
-
Database Setup
- Make sure MongoDB is running on your system
- Update the
MONGODB_URIin your.envfile if using a different connection string
-
Start the backend server
npm start
The backend will run on
http://localhost:8000 -
Start the frontend development server
cd frontend npm run devThe frontend will run on
http://localhost:5173
-
Build the frontend
npm run build
-
Start the production server
npm start
- POST
/upload - Description: Upload a file and get a download link
- Body:
multipart/form-datawith file - Response:
{ "path": "http://localhost:8000/files/{fileId}" }
- GET
/files/:fileId - Description: Download a file by its ID
- Response: File download
-
Upload a File
- Click the "Upload" button
- Select a file from your device
- The file will be automatically uploaded and a download link will be generated
-
Share the File
- Copy the generated download link
- Share the link with others
- Recipients can click the link to download the file
-
Download Files
- Click the "Download" button to download the file directly
- Or click the link to open it in a new tab
- Files are stored in the
fileFolder/directory - Each file gets a unique folder name (hash-based)
- File metadata (path, name, upload date) is stored in MongoDB
- Original filenames are preserved for downloads
- Files are stored with generated names to prevent conflicts
- No file type restrictions (configure as needed)
- CORS is enabled for cross-origin requests
- Consider adding file size limits and type validation for production use
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
This project is licensed under the ISC License.
-
MongoDB Connection Error
- Ensure MongoDB is running
- Check the connection string in
.env
-
File Upload Fails
- Check file size limits
- Ensure the
fileFolderdirectory exists and is writable
-
CORS Issues
- Verify the
VITE_BACKEND_URLmatches your backend URL - Check that CORS is properly configured
- Verify the
- Use
nodemonfor automatic server restarts during development - Check browser console for frontend errors
- Monitor server logs for backend issues
- Use MongoDB Compass to inspect uploaded file metadata