Target a directory for easily sharing files using HTTP.
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.
- 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
- Node.js (version 14 or higher recommended)
- npm
- Clone the repository:
git clone https://github.com/nojronatron/web-dir.git
cd web-dir- Install dependencies:
npm install- Configure the server by creating a
.envfile:
cp .env.example .env- Edit the
.envfile and set theDIR_SHAREvariable to the directory you want to share:
DIR_SHARE=/path/to/your/shared/directory
PORT=3000
# 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:fixStart 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 startThe 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.
To run the web server as a service on Debian Bookworm (Raspberry Pi):
- Create a systemd service file:
nano /etc/systemd/system/web-dir.service- 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- Reload systemd to recognize the new service:
systemctl daemon-reload- Enable the service to start on boot:
systemctl enable web-dir.service- Start the service:
systemctl start web-dir.service- Check the service status:
systemctl status web-dir.service- View service logs:
journalctl -u web-dir.service -f- 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
To completely remove the web-dir service:
- Stop the service:
systemctl stop web-dir.service- Disable the service:
systemctl disable web-dir.service- Remove the service file:
rm /etc/systemd/system/web-dir.service- Reload systemd:
systemctl daemon-reload- Reset any failed states:
systemctl reset-failedNote: Ensure Node.js is installed at /usr/bin/node. Check with which node and adjust the ExecStart path if necessary.
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 sharePORT(optional): The port number for the web server (default: 3000)
PORT- Server port (default: 3000)SERVE_DIR- Directory to serve files from (default: current working directory)
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.
See LICENSE file for details.