Many dev tools can run simple test web server, but to be able to access them for other computers on local network need to configure Windows firewall. This is the command, need to run as admin.
netsh advfirewall firewall add rule name="Node Port 3000" dir=in action=allow protocol=TCP localport=3000
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = 3000;
// Use '0.0.0.0' to listen on all network interfaces, not just localhost
const HOST = '0.0.0.0';
const server = http.createServer((req, res) => {
// Build file path from current directory and requested URL
let filePath = path.join(__dirname, req.url);
// If the request is for a directory, try to serve index.html
if (req.url === '/') {
filePath = path.join(__dirname, 'index.html');
}
// Check if the file exists
fs.readFile(filePath, (err, content) => {
if (err) {
// Handle file not found (404)
res.writeHead(404, { 'Content-Type': 'text/plain' });
res.end('404 Not Found');
} else {
// Serve the file with a 200 OK status
// In a real-world scenario, you would want a more robust MIME type handling,
// but this is a minimal example.
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(content, 'utf-8');
}
});
});
server.listen(PORT, HOST, () => {
console.log(`Server running at http://${HOST}:${PORT}/`);
console.log('Serving files from directory:', __dirname);
});
or just this with python
> python3 -m http.server 8000 --bind 0.0.0.0
or
import http.server
import socketserver
PORT = 8000
# By using "", the server will listen on all interfaces (0.0.0.0)
HANDLER = http.server.SimpleHTTPRequestHandler
with socketserver.TCPServer(("", PORT), HANDLER) as httpd:
print(f"Serving at port {PORT}...")
# This will print the actual address the server is binding to
print(f"Accessible via: http://{httpd.server_address[0]}:{PORT}")
httpd.serve_forever()
or with Go
package main
import (
"log"
"net/http"
)
func main() {
// Serve files from the "static" directory.
// You can change "static" to any directory path you wish to serve.
fs := http.FileServer(http.Dir("./static"))
// Handle all requests with the file server handler.
// The "/" pattern in Go matches all request paths.
http.Handle("/", fs)
// Listen on all network interfaces ("") on port 8080.
// Use ":8080" to listen on localhost only, or "" to listen on all addresses.
port := ":8080"
log.Printf("Serving on all addresses on port %s...\n", port)
err := http.ListenAndServe(port, nil)
if err != nil {
log.Fatal(err)
}
}
or with DotNet/C#
// Program.cs
var builder = WebApplication.CreateBuilder(args);
// Configure Kestrel to listen on all IP addresses (0.0.0.0) on port 8080
builder.WebHost.UseUrls("http://*:8080"); // Or use "http://*:*" to use default ports
var app = builder.Build();
// Enable serving static files (e.g., from the 'wwwroot' folder)
app.UseStaticFiles();
// Optional: Add a simple minimal API endpoint
app.MapGet("/", () => "Hello from Minimal File Server!");
app.Run();