TanStack Start applications can be deployed to any Node.js server environment, including traditional VPS servers, Docker containers, and container orchestration platforms like Kubernetes.
Prerequisites
- Node.js 18+ installed on your server
- A TanStack Start application
- Basic knowledge of server management
Configuration
Install Nitro
TanStack Start uses Nitro as the build adapter for Node.js deployment. Install the nightly version:
Or add to your package.json:
Update Vite Config
Add the Nitro plugin to your vite.config.ts:
Nitro v3 with Vite Environments API is under active development. Please report any issues you encounter.
Build Scripts
Ensure your package.json has the correct build and start scripts:
Building for Production
Build your application:
This creates a .output directory with:
.output/server/ - Server bundle
.output/public/ - Static assets (client-side code, images, etc.)
Running in Production
Basic Usage
Start your application:
Or directly with Node:
With Environment Variables
Configuration
Set the port via environment variable:
FastResponse
Get ~5% throughput improvement with srvx’s optimized Response:
- Install srvx:
- Add to your server entry point (
src/server.ts):
This optimization uses srvx’s _toNodeResponse() path to avoid Web Response to Node.js conversion overhead.
Docker Deployment
Dockerfile
Create a Dockerfile for your application:
Docker Compose
Create a docker-compose.yml for local testing:
Build and Run
Process Management
PM2
PM2 is a production process manager for Node.js applications:
Install PM2
Create PM2 Config
Create ecosystem.config.js:
Start with PM2
Auto-Start on Reboot
systemd Service
Create a systemd service file /etc/systemd/system/tanstack-start.service:
Enable and start the service:
Reverse Proxy
Nginx
Create an Nginx configuration:
Apache
Enable required modules:
Create Apache configuration:
SSL/TLS Configuration
Let’s Encrypt with Certbot
Install Certbot:
Obtain certificate:
Certbot automatically configures Nginx with SSL.
Environment Variables
.env File
Create a .env file (don’t commit to version control):
Load Environment Variables
Use dotenv in development:
In production, set variables directly:
Or use PM2’s environment configuration (see PM2 section above).
Monitoring and Logging
Application Logs
Log to files:
Health Checks
Add a health check endpoint:
Scaling
Horizontal Scaling
Run multiple instances behind a load balancer:
- Deploy multiple server instances
- Configure load balancer (Nginx, HAProxy, AWS ALB, etc.)
- Use shared session storage (Redis)
Cluster Mode
Use Node.js cluster module or PM2 cluster mode (shown above) to utilize all CPU cores.
Security Best Practices
- Use environment variables for sensitive data
- Keep Node.js updated to latest LTS version
- Run as non-root user (use
www-data or create dedicated user)
- Use HTTPS with valid SSL certificates
- Set security headers via reverse proxy
- Rate limiting to prevent abuse
- Regular security updates for dependencies
Resources
Troubleshooting
Port Already in Use
Memory Issues
Increase Node.js memory limit:
Build Errors
- Ensure all dependencies are installed:
pnpm install
- Clear build cache:
rm -rf .output
- Verify Nitro configuration in
vite.config.ts
Runtime Errors
- Check application logs
- Verify environment variables are set
- Test locally:
pnpm build && pnpm start
- Check file permissions on server