gitmyhub

http-server

JavaScript ★ 14k updated 2mo ago

A simple, zero-configuration, command-line http server

Zero-configuration command-line tool that instantly serves any folder as a website over HTTP, one command turns your local files into a web server viewable in any browser.

JavaScriptNode.jsnpmDockersetup: easycomplexity 1/5

http-server is a small command-line program that serves files from a folder over the web. The README describes it as a simple, zero-configuration static HTTP server. In plain terms, you point it at a folder on your computer and it makes the files in that folder available in a web browser, usually at http://localhost:8080. 'Zero-configuration' means you do not have to set up a config file first, you just run one command. 'Static' means it serves files as they are, such as HTML, images, and scripts, rather than generating pages on the fly.

The README says it is simple enough for testing, local development, and learning, while still being capable enough for production use. This makes it a common choice when someone just wants to preview a website they are building, or share a folder of files quickly.

Installing it is flexible. You can run it without installing through npx http-server, install it globally with npm or Homebrew so it is available anywhere from the command line, add it as a dependency in a project, or build a Docker image from the included Dockerfile. Once running, the path you give defaults to a ./public folder if it exists and otherwise the current folder.

A large part of the README is a table of options. These let you change the port and address, turn directory listings on or off, enable gzip or brotli compression, set how long files are cached, add custom response headers, require a username and password, and proxy requests that cannot be served locally to another URL. There are also notes on two 'magic' files: index.html is served by default for a folder, and 404.html is shown when a file is not found, which is handy for single-page apps.

The final sections explain how to enable HTTPS using OpenSSL to create a certificate and key, then running the server with the secure options.

Where it fits