http-server is a Node.js CLI tool that serves files from a directory with sensible defaults for local testing, development, and learning.
Overview
http-server serves static content from a chosen folder without extra setup. A default path prefers ./public when it exists, otherwise the current directory. It is intended for quick local hosting during development or demos rather than as a full production stack, though the project notes it can handle production-style serving when configured.
The CLI exposes controls for port, bind address, directory listings, cache lifetime, gzip and brotli precompressed files, CORS and related headers, TLS with custom certificates, basic authentication, proxy forwarding, SPA-friendly 404 handling, and robots.txt generation. Magic files such as index.html and 404.html enable single-page application hosting patterns.
You can install it globally through npm or Homebrew, add it as a project dependency, invoke it once with npx without installing, or build and run a container from the supplied Dockerfile when you need an isolated environment.
Logging options cover client IP addresses, UTC timestamps, custom response headers, and silent modes, while connection timeouts and allowed host lists help constrain how the server behaves on a machine.
Key features
- Static file serving from a path
- Directory listings and index files
- Gzip and brotli static compression
- CORS and security header switches
- HTTPS with certificate paths
- Basic auth and proxy modes
- SPA-friendly 404.html support
- npx on-demand execution
Use cases
- Local frontend previews
- Sharing build output on a LAN
- Teaching HTTP static hosting
- Quick SPA prototype hosting
- Temporary file drops during development