Create a Simple Static Web Server with `http-server`
When you need to test static HTML, CSS, JavaScript, images, or a generated site locally, the Node.js package http-server provides a small command-line server with minimal setup.
Run It Without a Global Install
If Node.js and npm are already installed, you can run the package with npx:
npx http-server .The final . means “serve the current directory.” The command prints the local addresses and port it is using.
A global installation also works:
npm install -g http-server
http-server .Using npx avoids requiring a machine-wide package installation for occasional use.
Choose a Port
npx http-server . -p 3000Open the Browser Automatically
npx http-server . -oEnable CORS Headers
For development scenarios that intentionally require cross-origin access:
npx http-server . --corsDo not enable permissive CORS automatically in production; configure origins according to your application’s security requirements.
Disable or Adjust Caching During Development
http-server supports cache-related options. Check the installed version’s help for the exact flags:
npx http-server --helpThis is preferable to relying on remembered flags because CLI options can evolve between versions.
Development Tool, Not a Production Architecture
http-server is convenient for local static-file testing and simple internal previews. A production deployment normally needs deliberate TLS, caching, compression, headers, logging, access controls, monitoring, and deployment practices supplied by a production web server or hosting platform.
Conclusion
Use http-server when you need a quick local HTTP origin instead of opening files directly from disk. npx http-server . is enough for most temporary development workflows, with optional flags for ports, browser opening, and CORS.