nsyte serve
Alias:
srv—nsyte srvis equivalent tonsyte serve.
Serve a local directory over HTTP for development and testing. Useful for previewing your nsite files before deploying them. The server binds to localhost only and supports directory listing.
Usage
nsyte serve [options]Options
-p, --port <port>: Port number for the local server (default:8080)-d, --dir <dir>: Directory to serve (defaults to current directory) (default:".")
Examples
Basic Serve
nsyte serveServes the current directory on http://localhost:8080.
Custom Port
nsyte serve --port 3000Serves on http://localhost:3000.
Custom Directory
nsyte serve --dir ./publicServes files from the ./public directory instead of the current directory.
What It Does
The serve command:
- Resolves the directory: Defaults to the current working directory; override with
-d, --dir - Starts an HTTP server: Listens on the chosen port (default
8080) onlocalhost - Serves files with directory listing enabled: Files are served via Deno's standard
serveDirhelper, which sets MIME types automatically and renders an index for directories without anindex.html
Use Cases
Preview Before Deploy
Quickly preview a built site directory before running nsyte deploy:
nsyte serve --dir ./distDifferent Project Layout
Serve a non-default directory while keeping the project's .nsite/config.json intact:
nsyte serve --dir ./public --port 3000Limitations
- Localhost only: The server binds to
localhost. There is no--hostoption; for sharing a preview across a LAN, use a separate tool such asssh -Ror a tunnel. - No SPA fallback:
nsyte servedoes not read.nsite/config.json, so the configuredfallbackis not applied. Non-existent paths return404rather than falling through toindex.html. If you need SPA-style routing during local preview, deploy to a staging nsite or use a dedicated SPA dev server. - No live reload: File changes do not trigger an automatic browser reload.
Troubleshooting
Port Already in Use
Error: Port 8080 is already in useSolution: Use a different port:
nsyte serve --port 3001Permission Denied
Error: Permission denied binding to port 80Solution: Use a port above 1024:
nsyte serve --port 8080Directory Not Found
Directory not found: /absolute/path/to/dirSolution: Confirm the path passed to --dir exists relative to the current working directory.
Related Commands
nsyte deploy- Deploy your files after testing locallynsyte run- Run a resolver server for npub subdomainsnsyte validate- Validate your configurationnsyte debug- Debug your published nsite
Inherits global options. See global options.