Skip to content

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.

License

Notifications You must be signed in to change notification settings

ZayanMuhammed/fileshare

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

13 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

File Share Server

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.

File Share Demo Node.js License

image

πŸš€ Features

  • 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

πŸ› οΈ Technology Stack

  • Backend: Node.js, Express.js
  • Database: MySQL/MariaDB (optional)
  • File Handling: Multer middleware
  • Frontend: HTML5, CSS3, JavaScript (ES6+)
  • Storage: Local filesystem

πŸ“¦ Installation

Prerequisites

  • Node.js (version 14 or higher)
  • npm or yarn
  • MySQL/MariaDB (optional, for database logging)

Quick Start

  1. Clone the repository:

    git clone https://github.com/ZayanMuhammed/fileshare.git
    cd fileshare
  2. Install dependencies:

    npm install
  3. Create uploads directory:

    mkdir uploads
  4. Start the server:

    npm start
  5. Open your browser and navigate to:

    http://localhost:3000/fileshare.htm
    

πŸ—„οΈ Database Setup (Optional)

If you want to enable database logging of file uploads:

Install MariaDB/MySQL

For Debian/Ubuntu:

sudo apt update
sudo apt install mariadb-server mariadb-client

For Arch Linux:

sudo pacman -Syu
sudo pacman -S mariadb

Start and Configure Database

  1. Start MariaDB service:

    sudo systemctl start mariadb
    sudo systemctl enable mariadb
  2. Secure installation:

    sudo mysql_secure_installation
  3. 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;
  4. 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
    });

πŸš€ Usage

If you want a login splash that can also start the server, use the login module described below.

Uploading Files

  1. Open the web interface at http://localhost:3000/fileshare.htm
  2. Click on the upload area or drag and drop files
  3. Select your file(s)
  4. Click the "Upload" button
  5. Files will be uploaded to the uploads/ directory

Downloading Files

  • 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

API Endpoints

The server provides the following REST API endpoints:

Upload File

POST /upload
Content-Type: multipart/form-data

Form field: uploadedFile (file)

List Files

GET /files

Response:

["file1.txt", "file2.jpg", "document.pdf"]

Download File

GET /uploads/{filename}

πŸ“ Project Structure

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

πŸ” Login Module

image

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.

βš™οΈ Configuration

Server Configuration

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

Frontend Customization

  • Styling: Edit fileshare.css for visual customization
  • Behavior: Modify sql-data.js for frontend functionality
  • Interface: Update fileshare.htm for layout changes

πŸ”§ Advanced Configuration

Adding File Size Limits

const upload = multer({ 
    storage: storage,
    limits: {
        fileSize: 10 * 1024 * 1024, // 10MB limit
    }
});

Adding File Type Restrictions

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);
        }
    }
});

Environment Variables

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

🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License. See the LICENSE file for details.

πŸ‘€ Author

Zayan Muhammed

πŸ™ Acknowledgments

  • Express.js team for the excellent web framework
  • Multer developers for file upload handling
  • The Node.js community for continuous support

πŸ“Š Project Status

This project is actively maintained. Feel free to report issues or suggest improvements!


🚨 Security Note

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

About

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.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published