Esta página se muestra en inglés. Una traducción al español está en curso.
ConfigsMay 29, 2026·3 min de lectura

http-server — Zero-Config Static File Server for Development

A simple, zero-configuration command-line HTTP server for serving static files. Ideal for quickly previewing HTML/CSS/JS projects, testing single-page applications locally, and serving build artifacts during development.

Listo para agents

Instalación lista para agent

Este activo puede instalarse después de elegir el runtime, revisar el plan y ejecutar el comando correspondiente.

Native · 98/100Política: permitir
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Single
Confianza
Confianza: Established
Entrada
http-server Overview
Comando de instalación directa
npx -y tokrepo@latest install 0486fa5b-5b7b-11f1-9bc6-00163e2b0d79 --target codex

Ejecutar después de confirmar el plan con dry-run.

Introduction

http-server is a zero-configuration command-line HTTP server for Node.js. It serves static files from any directory, making it one of the simplest ways to preview web projects, test build output, or host files locally during development without configuring Nginx, Apache, or a framework dev server.

What http-server Does

  • Serves any directory as a static file server with a single command
  • Supports HTTPS via self-signed certificates or custom TLS key/cert pairs
  • Enables CORS headers with a single flag for cross-origin API testing
  • Provides gzip and brotli compression for served files
  • Falls back to index.html for single-page application routing with the --proxy flag

Architecture Overview

http-server is a thin wrapper around Node.js's built-in HTTP module combined with the union middleware framework and ecstatic static file serving library. When invoked, it binds to a port, resolves file paths relative to the specified root directory, and serves matching files with appropriate MIME types. Directory listings are generated automatically when no index file exists.

Self-Hosting & Configuration

  • Run with npx http-server for instant usage without global installation
  • Use -p to specify a custom port (default is 8080)
  • Enable HTTPS with -S and optionally provide -C (cert) and -K (key) files
  • Set -c-1 to disable caching during active development
  • Use --proxy http://localhost:8080? to redirect 404s to the root for SPA client-side routing

Key Features

  • True zero-configuration: just point it at a directory and go
  • HTTPS support with automatic self-signed certificate generation
  • CORS enabled via --cors flag for frontend development against local APIs
  • Gzip compression support to simulate production-like file serving
  • Lightweight with no build step, framework, or config file required

Comparison with Similar Tools

  • serve (Vercel) — similar zero-config static server with built-in SPA support and cleaner directory listings; http-server has been around longer
  • live-server — adds live reload on file changes; http-server requires a separate file watcher
  • Python http.server — built into Python but lacks CORS, HTTPS, and compression options
  • BrowserSync — provides live reload and multi-device sync; heavier than http-server for simple file serving

FAQ

Q: Can http-server serve single-page applications? A: Yes, use the --proxy flag to redirect unmatched routes back to index.html.

Q: How do I enable HTTPS? A: Pass the -S flag. http-server will generate a self-signed certificate automatically, or you can supply your own with -C and -K.

Q: Does http-server support live reload? A: No, http-server is a static file server only. For live reload, combine it with a file watcher like nodemon or use live-server instead.

Q: How do I disable caching? A: Use -c-1 to set the cache time to negative one second, effectively disabling browser caching.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados