python -m http.server 8000
Serves the current directory on port 8000.
go run -e "package main; import ('net/http'); func main() {http.ListenAndServe(':8000', http.FileServer(http.Dir('.')))}"
Serves the current directory on port 8000.
Using the cargo install simple-http-server
(install if not done yet):
simple-http-server --port 8000
ruby -run -e httpd . -p 8000
Serves the current directory on port 8000.
php -S 0.0.0.0:8000
Serves the current directory on port 8000.
perl -MHTTP::Server::Brick -e '$s = HTTP::Server::Brick->new(port => 8000); $s->mount("/" => {path => "."}); $s->start'
Serves the current directory on port 8000.
Apache typically requires configuration, but to launch a temporary server in the current directory, use:
httpd -f /dev/null -c "ServerRoot ." -c "Listen 8000" -c "DocumentRoot $(pwd)"
Using a small embedded HTTP server:
jshell -R -e 'import com.sun.net.httpserver.*; var server = HttpServer.create(new InetSocketAddress(8000), 0); server.createContext("/", h -> {var os = h.getResponseBody(); h.sendResponseHeaders(200, 0); os.write("Hello, World!".getBytes()); os.close();}); server.start();'
Install http-server
globally if not done yet:
npm install -g http-server
Then run:
http-server -p 8000
Alternatively, a one-liner directly in Node.js:
node -e "require('http').createServer((req, res) => res.end('Hello, World!')).listen(8000)"
while true; do echo -e "HTTP/1.1 200 OK\n\nHello, World!" | nc -l 8000; done
Not a file server, but serves a basic HTTP response.
Using the lua-http
library (install if not done yet):
lua -e 'local http = require("http.server").new("0.0.0.0", 8000); http:run()'
npx http-server
Serves the current directory on a default port.
deno run --allow-net=:8000 https://deno.land/std/http/file_server.ts
Serves the current directory on port 8000.
For a more feature-rich Python HTTP server:
pip install flask
python -c "from flask import Flask, send_from_directory; app = Flask(__name__); app.route('/<path:path>')(lambda path: send_from_directory('.', path)); app.run(port=8000)"
A minimal Flask server serving static files from the current directory on port 8000.
If you want to keep things in vanilla Node.js:
node -e "import('http').then(({createServer})=>createServer((_,res)=>res.end('Hello, World!')).listen(8000))"
Simple ES6-compatible HTTP server.
For Windows users, PowerShell offers an easy solution:
Start-Process -NoNewWindow powershell -ArgumentList '-command $h=New-Object Net.HttpListener;$h.Prefixes.Add("http://*:8000/");$h.Start();while($h.IsListening){$c=$h.GetContext();$r=$c.Response;$r.OutputStream.Close()}'
Starts a simple HTTP server on port 8000.
Caddy is a powerful, secure web server with automatic HTTPS:
caddy file-server --listen :8000
Serves the current directory on port 8000 with minimal configuration.
For embedded systems and lightweight environments:
busybox httpd -f -p 8000
A simple HTTP server for lightweight systems.
stack exec runghc -- -e "import Network.Wai.Handler.Warp (run); import Network.Wai.Application.Static (staticApp, defaultFileServerSettings); run 8000 (staticApp (defaultFileServerSettings "."))"
Serves the current directory using Haskell.