vinext build. Supports SSR, static file serving, compression, and middleware.
Usage
Options
number
default:"3000"
Port to listen on. Can also use the short form
-p. Defaults to the PORT environment variable if set.string
default:"0.0.0.0"
Hostname to bind to. Can also use the short form
-H.Default is
0.0.0.0 (all interfaces) in production, unlike dev mode which defaults to localhost.flag
Show help for this command. Can also use
-h.Behavior
Server Implementation
The production server is implemented inserver/prod-server.ts and provides:
- Static asset serving: Serves files from
dist/client/ - SSR rendering: Server-side renders pages on request
- API route handling: Routes
/api/*requests to server handlers - Compression: Gzip and Brotli compression for text-based responses
- Streaming SSR: Supports React 18 streaming for App Router
Request Handling
The production server handles requests in this order:- Middleware/Proxy (if exists)
- Redirects (from
next.config) - Rewrites (from
next.config) - Static assets (
dist/client/) - API routes (
/api/*) - Page routes (SSR)
- 404 page (if no match)
Response Compression
The server automatically compresses responses:SSR Output
For Pages Router, the server loads the SSR entry:Examples
Basic Usage
Start production server on default port (3000):Custom Port
Start on port 8080:Using Environment Variables
.env.production:
Bind to Localhost Only
For security on shared hosts:Production npm Script
Add topackage.json:
Deployment
Node.js Deployment
For traditional Node.js hosting:Docker Deployment
Cloudflare Workers
For Cloudflare Workers, usevinext deploy instead:
Process Management
Using PM2
For production deployments with auto-restart:Using systemd
Create/etc/systemd/system/my-app.service:
Performance
Response Times
Typical server response times:Benchmarks from a medium-complexity app on modern hardware. Actual times vary by complexity.
Compression Impact
Typical compression ratios:Caching Strategy
The server sets these cache headers:Troubleshooting
”dist/ directory not found”
You forgot to build first:Port Already in Use
Another process is using the port:Pages Not Loading (404)
Check the build output:High Memory Usage
The server loads all pages into memory. For very large apps:-
Increase Node.js heap size:
-
Or deploy to Cloudflare Workers (no memory limits):
Monitoring
Health Check Endpoint
Add a health check page:Access Logs
The production server logs all requests to stdout:Next Steps
deploy Command
Deploy to Cloudflare Workers
Deployment Guide
Learn about deployment options