Static Node.js builds
1 min read
Updated 20 hours ago
Static Node.js builds
Deploy pre-built Node.js applications with optimized static file serving through Nginx.
When to use static mode
Choose static deployment when your application:
- Generates all content at build time
- Doesn't require server-side logic
- Can run entirely in the browser
- Benefits from CDN and caching
SPA routing configuration
Single-page applications require all routes to serve index.html. Ploi Cloud automatically configures Nginx to handle SPA routing:
- All routes return index.html
- Direct file requests (CSS, JS, images) are served normally
- 404s for missing assets return proper 404 status
Build output structure
Your build should generate:
/var/www/html/
└── index.html
Optimizing static builds
Asset optimization
- Enable build-time compression
- Use content hashing for cache busting
- Optimize images and fonts
- Minimize JavaScript bundles
Build commands
# Install dependencies and build
npm ci && npm run build
# With environment check
npm ci && NODE_ENV=production npm run build
Converting from runtime to static
If your Node.js app can work as static:
- Remove server-side code
- Build to static files
- Remove start command in settings
- Ensure build outputs to correct directory
- Deploy changes