nsyte serve
¶
Build and serve your local nsite files for development and testing purposes. This command creates a local development server that serves your files as they would appear when published.
Usage¶
Options¶
--port <port>
: Port number to serve on (default: 3000)--host <host>
: Host to bind to (default: localhost)--open
: Open the site in your default browser--help
: Show help information
Examples¶
Basic Serve¶
Serves the local nsite on http://localhost:3000
.
Custom Port¶
Serves on http://localhost:8080
.
Custom Host¶
Serves on all network interfaces, accessible from other devices on your network.
Open in Browser¶
Serves the site and automatically opens it in your default web browser.
What It Does¶
The serve command:
- Reads Configuration: Loads your
.nsite/config.json
to understand the project structure - Builds Files: Processes your local files according to nsite rules
- Applies Fallback: Uses the configured fallback file for client-side routing
- Serves Content: Starts a local HTTP server to serve your files
- Live Reload: Automatically reloads when files change (if supported)
File Processing¶
The serve command mimics how your nsite will behave when published:
Fallback Handling¶
If you have a fallback
configured in your config (e.g., "/index.html"
), the serve command will:
- Serve the fallback file for any non-existent paths
- Support client-side routing for SPAs (React, Vue, etc.)
Content Types¶
Files are served with appropriate MIME types:
- .html
→ text/html
- .css
→ text/css
- .js
→ application/javascript
- .json
→ application/json
- Images → appropriate image types
- And more...
Directory Structure¶
The serve command respects your project's directory structure and serves files from the configured source directory.
Development Features¶
Hot Reload¶
The serve command can watch for file changes and automatically reload the browser (feature availability depends on implementation).
Error Handling¶
- Shows helpful error messages for missing files
- Serves fallback content for 404 errors
- Displays server logs for debugging
Network Access¶
When using --host 0.0.0.0
, you can access your nsite from:
- Other devices on your network
- Mobile devices for testing
- Virtual machines
Use Cases¶
SPA Development¶
For single-page applications with client-side routing:
The fallback configuration ensures all routes are handled by your SPA.
Mobile Testing¶
Test your nsite on mobile devices:
Then access http://[your-ip]:3000
from your mobile device.
Production Preview¶
Preview how your nsite will look when published:
This gives you a local preview of the exact content that will be uploaded.
Configuration¶
The serve command respects these configuration options from .nsite/config.json
:
fallback
: File to serve for 404 errors (enables SPA routing)- Source directory settings
- File ignore patterns (from
.nsite-ignore
)
Comparison with Other Servers¶
vs. python -m http.server
¶
- ✅ Respects nsite fallback configuration
- ✅ Proper MIME types
- ✅ Understands nsite project structure
vs. npx serve
¶
- ✅ No Node.js dependency
- ✅ nsite-specific features
- ✅ Integrated with nsite configuration
vs. Production nsite¶
- ⚠️ Local files (not from Blossom)
- ⚠️ No relay integration
- ✅ Same fallback behavior
- ✅ Same file structure
Troubleshooting¶
Port Already in Use¶
Solution: Use a different port:
Permission Denied¶
Solution: Use a port above 1024 or run with sudo (not recommended):
Files Not Found¶
Solution: Ensure you're running the command from your project directory with a valid .nsite/config.json
.
Related Commands¶
nsyte upload
- Upload your files after testing locallynsyte run
- Run a resolver server for npub subdomainsnsyte validate
- Validate your configurationnsyte debug
- Debug your published nsite