A lightweight, secure HTTP file server for exposing files from a local directory via HTTP requests.
File Exposer is a simple Node.js-based HTTP server that allows you to serve files from the server's directory through HTTP GET requests. It's designed for quick file sharing and testing scenarios where you need to make local files accessible via HTTP.
- 🚀 Simple Setup - No configuration required, just run and go
- 🔒 Security Built-in - Directory traversal protection to prevent unauthorized access
- 📁 Multiple MIME Types - Supports common file formats with proper content-type headers
- ⚡ Lightweight - Uses only Node.js built-in modules, no external dependencies
- 🎯 RESTful API - Clean URL structure for accessing files
The server automatically detects and serves files with appropriate MIME types:
- Web:
.html,.htm,.css,.js,.aspx - Data:
.json,.xml,.txt - Images:
.png,.jpg,.jpeg,.gif,.svg,.ico - Documents:
.pdf,.zip - Fallback: Any other file type is served as
application/octet-stream
- Clone or download this repository
- Ensure you have Node.js installed (no additional packages required)
# No npm install needed - uses only Node.js built-in modules!node expose.jsThe server will start on http://localhost:4567 by default.
To access a file, simply append the filename to the server URL:
http://localhost:4567/{filename}
Examples:
# Access an HTML file
http://localhost:4567/index.html
# Access an image
http://localhost:4567/logo.png
# Access a JSON file
http://localhost:4567/data.json
# Access files in subdirectories
http://localhost:4567/assets/style.cssRetrieves the requested file from the server directory.
Parameters:
filename(path parameter) - The name/path of the file relative to the server directory
Responses:
| Status Code | Description |
|---|---|
| 200 | File found and returned successfully |
| 400 | No file specified or attempting to read a directory |
| 403 | Access denied (directory traversal attempt detected) |
| 404 | File not found |
| 500 | Internal server error |
Success Response (200):
Content-Type: {appropriate MIME type}
{file contents}
Error Response Examples:
// 400 - No file specified
{
"error": "No file specified",
"usage": "GET /{filename} - Returns the requested file from the server directory"
}
// 403 - Directory traversal attempt
{
"error": "Access denied: Directory traversal not allowed"
}
// 404 - File not found
{
"error": "File not found",
"path": "nonexistent.txt"
}The server implements multiple layers of protection against directory traversal attacks:
- Pattern Detection - Blocks requests containing
..,\.., or../ - Path Validation - Ensures the resolved file path stays within the server directory
- Normalized Path Checking - Uses Node.js
path.join()to prevent path manipulation
Blocked Examples:
# These will all return 403 Forbidden
http://localhost:4567/../etc/passwd
http://localhost:4567/../../secret.txt
http://localhost:4567/subfolder/../../config.jsonYou can modify the following constants in expose.js to customize the server:
const PORT = 4567; // Server port
const HOST = 'localhost'; // Server host- Local Development - Serve static files during development
- Quick File Sharing - Share files on a local network
- Testing - Test file downloads and MIME type handling
- Prototyping - Quickly expose files for web applications
- SharePoint Development - Serve local files for SharePoint customization testing
- Single Directory - Only serves files from the directory where
expose.jsis located - No Directory Listing - Cannot browse directories, must specify exact file paths
- No Authentication - No built-in user authentication or authorization
- Local Network Only - Designed for localhost/local network use, not production
The server provides detailed error messages for common scenarios:
- Missing File - Returns 404 with the requested path
- Directory Access - Returns 400 when trying to read a directory
- Security Violations - Returns 403 for directory traversal attempts
- Server Errors - Returns 500 with error details for unexpected issues
- Place
expose.jsin a directory with files you want to serve - Start the server:
node expose.js - Access files via browser or HTTP client:
curl http://localhost:4567/myfile.txt
Server won't start:
- Check if port 4567 is already in use
- Ensure Node.js is properly installed
File not found:
- Verify the file exists in the same directory as
expose.js - Check the file path (case-sensitive on some systems)
- Ensure you're not trying to access a directory
403 Forbidden:
- Remove any
..or path traversal characters from your request - Ensure the file is within the server directory
This project is provided as-is for personal and educational use.
Feel free to fork and modify this server for your specific needs. Common enhancements include:
- Adding authentication
- Supporting directory listing
- Implementing file upload
- Adding CORS headers
- Supporting HTTPS
Note: This server is intended for development and testing purposes. For production use, consider using established solutions like Express.js, Nginx, or Apache.