Skip to main content
Starts a production HTTP server to serve the output from vinext build. Supports SSR, static file serving, compression, and middleware.

Usage

You must run vinext build before vinext start. The start command serves the built output from the dist/ directory.

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 in server/prod-server.ts and provides:
Features:
  • 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:
  1. Middleware/Proxy (if exists)
  2. Redirects (from next.config)
  3. Rewrites (from next.config)
  4. Static assets (dist/client/)
  5. API routes (/api/*)
  6. Page routes (SSR)
  7. 404 page (if no match)

Response Compression

The server automatically compresses responses:
Encoding preference: Brotli > Gzip > Deflate > Identity Minimum threshold: 1024 bytes (files smaller than 1KB are not compressed)

SSR Output

For Pages Router, the server loads the SSR entry:
For App Router, the server loads the RSC entry:

Examples

Basic Usage

Start production server on default port (3000):
Output:

Custom Port

Start on port 8080:
Or:

Using Environment Variables

Or add to .env.production:

Bind to Localhost Only

For security on shared hosts:

Production npm Script

Add to package.json:
Then:

Deployment

Node.js Deployment

For traditional Node.js hosting:

Docker Deployment

Build and run:

Cloudflare Workers

For Cloudflare Workers, use vinext deploy instead:
This builds and deploys in one command. See the deploy command for details.

Process Management

Using PM2

For production deployments with auto-restart:

Using systemd

Create /etc/systemd/system/my-app.service:
Enable and start:

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:
Ensure both directories exist and contain files.

High Memory Usage

The server loads all pages into memory. For very large apps:
  1. Increase Node.js heap size:
  2. Or deploy to Cloudflare Workers (no memory limits):

Monitoring

Health Check Endpoint

Add a health check page:
Then monitor:

Access Logs

The production server logs all requests to stdout:
Redirect logs to a file:

Next Steps

deploy Command

Deploy to Cloudflare Workers

Deployment Guide

Learn about deployment options