A simple yet powerful file sharing web application built with Node.js and Express. Upload files through a modern web interface and share them instantly with others.

- 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
- Backend: Node.js, Express.js
- Database: MySQL/MariaDB (optional)
- File Handling: Multer middleware
- Frontend: HTML5, CSS3, JavaScript (ES6+)
- Storage: Local filesystem
- 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
If you want to enable database logging of file uploads:
For Debian/Ubuntu:
sudo apt update
sudo apt install mariadb-server mariadb-client
For 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
uploadedFile.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
/uploads
endpoint
The server provides the following REST API endpoints:
POST /upload
Content-Type: multipart/form-data
Form field: uploadedFile (file)
GET /files
Response:
["file1.txt", "file2.jpg", "document.pdf"]
GET /uploads/{filename}
fileshare/
βββ uploadedFile.js # Main server file
βββ fileshare.htm # Main web interface
βββ fileshare.css # Styles for the interface
βββ sql-data.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 (separate express server)
β βββ startweb.js # Serves login UI and exposes /run-script
β βββ login.htm # Login page
β βββ login.css # Login styles
β βββ login.js # Login client logic
β βββ your_script.sh # Starts main server (edit path inside)
β βββ README.md # This module's docs
βββ README.md # Root documentation

A minimal login gateway is available under login/ and runs on port 8080 by default.
- 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)
- On success it calls GET /run-script, which executes login/your_script.sh
- your_script.sh should cd to your project root and start node uploadedFile.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 uploadedFile.js
to modify:
- Port: Change
const port = 3000;
to your preferred port - Upload Directory: Modify the
destination
in multer configuration - File Size Limits: Add size limits to multer configuration
- CORS Settings: Modify CORS headers as needed
- Styling: Edit
fileshare.css
for visual customization - Behavior: Modify
sql-data.js
for frontend functionality - Interface: Update
fileshare.htm
for 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);
}
}
});
Create a .env
file for configuration:
PORT=3000
DB_HOST=localhost
DB_USER=fileshare_user
DB_PASSWORD=your_password
DB_NAME=fileshare
UPLOAD_DIR=uploads
- 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!
This application is intended for development and testing purposes and local use. For production use, please consider:
- Adding authentication and authorization
- 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