Static file serving and directory listing
open sourceMITself-hostablefree
serve is Vercel's command-line static file server for Node.js: npx serve in a folder serves a static site, a single-page app or a single file on your machine or local network, with a browsable directory listing. Flags turn on single-page-app rewrites to index.html (--single), CORS headers, HTTPS with your own certificate and key, symlinks and custom listen addresses, and gzip compression and ETags are on by default. Rewrites, redirects and headers are configured in a serve.json file, using the options of serve-handler, the same core published as middleware for Node's own HTTP server. It's MIT licensed; the README recommends Vercel for production hosting.
Problems it solves
- quickly serve a folder of static files over HTTP to test my build
- my single-page app's routes 404 when I refresh in a local static server
- share a folder with another device on my local network from the terminal
- preview a production build of a React app without setting up nginx
- serve local files with CORS headers so another dev server can fetch them
- test my static site over HTTPS locally with my own certificate
- add static file serving with rewrites and headers to an existing Node HTTP server
Features
- serves static sites, single-page apps and single files
- directory listing UI
- --single rewrites unknown paths to index.html for SPAs
- --cors headers
- HTTPS with --ssl-cert, --ssl-key and --ssl-pass
- gzip compression and ETags on by default
- serve.json config for rewrites, redirects and headers
- copies the local URL to the clipboard and switches port when busy
- serve-handler middleware for Node's HTTP server
Capabilities
| Has a command line tool | plan not known |
|---|
Alternatives
The same job
These do what serve does.
