Skip to content

nojronatron/web-dir

Repository files navigation

web-dir

Target a directory for easily sharing files using HTTP.

Description

A simple Express.js 5 web server that allows remote anonymous users to view and download files from a local directory. Designed for use on completely private networks with no authentication required.

Features

  • List all files in a shared directory with filename and creation date
  • Download files by clicking on them
  • Clean, simple web interface
  • No external dependencies beyond Express.js
  • Configurable via environment variables

Requirements

  • Node.js (version 14 or higher recommended)
  • npm

Installation

  1. Clone the repository:
git clone https://github.com/nojronatron/web-dir.git
cd web-dir
  1. Install dependencies:
npm install
  1. Configure the server by creating a .env file:
cp .env.example .env
  1. Edit the .env file and set the DIR_SHARE variable to the directory you want to share:
DIR_SHARE=/path/to/your/shared/directory
PORT=3000

Development

# Install dependencies
npm install

# Build the project
npm run build

# Run in development mode
npm run dev

# Run tests
npm test

# Lint code
npm run lint

# Fix lint issues
npm run lint:fix

Usage

Start the server:

# Start the server (default port 3000, serves current directory)
npm start

# Specify custom directory and port
PORT=8080 SERVE_DIR=/path/to/directory npm start

The server will start on the port specified in your .env file (default: 3000).

Access the file listing by opening a web browser and navigating to:

http://localhost:3000

Click on any filename to download the file to your browser's default download directory.

Running as a Systemd Service

To run the web server as a service on Debian Bookworm (Raspberry Pi):

  1. Create a systemd service file:
nano /etc/systemd/system/web-dir.service
  1. Add the following configuration (adjust paths and environment variables as needed):
[Unit]
Description=Web Directory Server
After=network.target

[Service]
Type=simple
User=root
WorkingDirectory=/workspaces/web-dir
Environment="NODE_ENV=production"
Environment="PORT=3000"
Environment="SERVE_DIR=/path/to/your/shared/directory"
ExecStart=/usr/bin/node /workspaces/web-dir/server.js
Restart=on-failure
RestartSec=10
StandardOutput=journal
StandardError=journal

[Install]
WantedBy=multi-user.target
  1. Reload systemd to recognize the new service:
systemctl daemon-reload
  1. Enable the service to start on boot:
systemctl enable web-dir.service
  1. Start the service:
systemctl start web-dir.service
  1. Check the service status:
systemctl status web-dir.service
  1. View service logs:
journalctl -u web-dir.service -f

Service Management Commands

  • Stop the service: systemctl stop web-dir.service
  • Restart the service: systemctl restart web-dir.service
  • Disable auto-start on boot: systemctl disable web-dir.service
  • View recent logs: journalctl -u web-dir.service -n 50

Uninstalling the Service

To completely remove the web-dir service:

  1. Stop the service:
systemctl stop web-dir.service
  1. Disable the service:
systemctl disable web-dir.service
  1. Remove the service file:
rm /etc/systemd/system/web-dir.service
  1. Reload systemd:
systemctl daemon-reload
  1. Reset any failed states:
systemctl reset-failed

Note: Ensure Node.js is installed at /usr/bin/node. Check with which node and adjust the ExecStart path if necessary.

Configuration

The server is configured using environment variables in a .env file:

  • DIR_SHARE (required): The absolute or relative path to the directory containing files to share
  • PORT (optional): The port number for the web server (default: 3000)

Environment Variables

  • PORT - Server port (default: 3000)
  • SERVE_DIR - Directory to serve files from (default: current working directory)

Security Notes

This server is designed for use on completely private networks only. It has:

  • No user authentication or authorization
  • No rate limiting
  • No caching or proxy support

Do not expose this server to the public internet.

License

See LICENSE file for details.

About

Target a PiCam image directory for remote viewing.

Topics

Resources

License

Stars

Watchers

Forks

Contributors 2

  •  
  •