- Drag & Drop File Upload: Modern, intuitive file upload interface
- Instant File Sharing: Upload and share files immediately
- File Management: View and download all uploaded files
- Database Logging: Optional MySQL/MariaDB integration for upload tracking
- CORS Enabled: Cross-origin requests supported
- Responsive Design: Works on desktop and mobile devices
- Real-time Updates: File list refreshes automatically after uploads
- Has Auth for Security: check if login first then only allowed in page
- Recovery: just in case if you for got your password
- Backend: Node.js, Express.js
- Database: MySQL/MariaDB (optional)
- File Handling: Multer middleware
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- Storage: Local filesystem
Note
New update!! v1.2.7: New recovery mode!!!
- Node.js (version 14 or higher)
- npm or yarn
- MySQL/MariaDB (optional, for database logging)
-
Clone the repository:
git clone https://github.com/ZayanMuhammed/fileshare.git cd fileshare -
Install dependencies:
npm install
-
Create uploads directory:
mkdir uploads
-
Start the server:
npm start
-
Open your browser and navigate to:
http://localhost:3000/fileshare.htm
Tip
If you are lazy like me just use the setup.sh file
If you want to enable database logging of file uploads:
For Debian/Ubuntu:
sudo apt update
sudo apt install mariadb-server mariadb-clientFor Arch Linux:
sudo pacman -Syu
sudo pacman -S mariadb-
Start MariaDB service:
sudo systemctl start mariadb sudo systemctl enable mariadb -
Secure installation:
sudo mysql_secure_installation
-
Create database and table:
mariadb -u root -p
CREATE DATABASE fileshare; USE fileshare; CREATE TABLE files ( id INT AUTO_INCREMENT PRIMARY KEY, filePath VARCHAR(255) NOT NULL, originalname VARCHAR(255) NOT NULL, mimetype VARCHAR(100) NOT NULL, size BIGINT NOT NULL, uploaded_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ); -- Create a user for the application CREATE USER 'fileshare_user'@'localhost' IDENTIFIED BY 'your_password'; GRANT ALL PRIVILEGES ON fileshare.* TO 'fileshare_user'@'localhost'; FLUSH PRIVILEGES;
-
Update database configuration in
server.js:const db = mysql.createPool({ host: 'localhost', user: 'fileshare_user', // your mariadb user password: 'your_password', // your mariadb password database: 'fileshare', // your mariadb database acquireTimeout: 60000, timeout: 60000, reconnect: true });
If you want a login splash that can also start the server, use the login module described below.
- Open the web interface at
http://localhost:3000/fileshare.htm - Click on the upload area or drag and drop files
- Select your file(s)
- Click the "Upload" button
- Files will be uploaded to the
uploads/directory
- All uploaded files are automatically listed on the main page
- Click on any filename to download the file
- Files are served statically from the
/uploadsendpoint
The server provides the following REST API endpoints:
POST /upload
Content-Type: multipart/form-data
Form field: server (file)GET /filesResponse:
["file1.txt", "file2.jpg", "document.pdf"]GET /uploads/{filename}fileshare/
βββ .env # Credentials and vars
βββ input.css
βββ output.css # tailwind css file
βββ tailwind.config.js #tailwind config
βββ auth-failed.htm # auth fail page
βββ warning.htm # warning page for log out
βββ auth-failed.css # style for fail page
βββ server.js # Main server file
βββ fileshare.htm # Main web interface
βββ fileshare.css # Styles for the interface
βββ setup.sh # for lazy devs like me
βββ client.js # Frontend JavaScript
βββ install-mariadb.sh # Database installation script
βββ package.json # Node.js dependencies
βββ uploads/ # Directory for uploaded files
βββ assets/ # Static assets (favicon, etc.)
βββ login/ # Login gateway
β βββ login.htm # Login page
β βββ login.css # Login styles
β βββ login.js # Login client logic
| βββ showPassword.htm # forgot password show here
β βββ README.md # This module's docs
βββ README.md # Root documentation
A minimal login gateway is available under login/
- Install and run:
cd login npm install node startweb.js - Open http://localhost:8080/login.htm
- Default demo credentials: admin / Password123 (change in login/login.js)
Important: /run-script executes a shell script. Keep it for local/dev. For production, use a proper auth flow and a process manager (pm2/systemd) instead of executing shell from HTTP.
Edit server.js to modify:
- Port: Change
const port = 3000;to your preferred port - Upload Directory: Modify the
destinationin multer configuration - File Size Limits: Add size limits to multer configuration
- CORS Settings: Modify CORS headers as needed
- Styling: Edit
fileshare.cssfor visual customization - Behavior: Modify
sql-data.jsfor frontend functionality - Interface: Update
fileshare.htmfor layout changes
const upload = multer({
storage: storage,
limits: {
fileSize: 10 * 1024 * 1024, // 10MB limit
}
});const upload = multer({
storage: storage,
fileFilter: (req, file, cb) => {
const allowedTypes = ['image/jpeg', 'image/png', 'application/pdf'];
if (allowedTypes.includes(file.mimetype)) {
cb(null, true);
} else {
cb(new Error('Invalid file type'), false);
}
}
});Important
Note that make a .env file to configure to your liking!
PORT=3000
DB_HOST=localhost
DB_USER=fileshare_user
DB_PASSWORD=your_password
DB=db_name
DISABLE_RECOVERY=false- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License. See the LICENSE file for details.
Zayan Muhammed
- GitHub: @ZayanMuhammed
- Email: zayan.shameermv@gmail.com
- Express.js team for the excellent web framework
- Multer developers for file upload handling
- The Node.js community for continuous support
This project is actively maintained. Feel free to report issues or suggest improvements!
Caution
This application is intended for development and testing purposes and local use. For >production use, please consider:
- Implementing file type validation
- Adding virus scanning for uploads
- Setting up proper HTTPS
- Configuring proper file storage and backup
- Adding rate limiting and other security measures
