Node.js je standard za real-time apps, API backends, SaaS, chat servers, IoT. Drugačiji deployment model od PHP-a — long-running processes, ne request-response cycle. Treba hosting koji to razumije. Ovo je vodič.
Node.js ukratko
- JavaScript runtime (V8 engine).
- Verzije: Node 20 LTS (do travnja 2026), Node 22 LTS (do travnja 2027), Node 24 (current).
- Event-loop, non-blocking I/O.
- Frameworks: Express, Fastify, NestJS, Koa, Hono.
- Real-time: Socket.IO, ws, native WebSocket.
Zašto Node nije standard PHP hosting
- Long-running process — ne pokreće se per-request kao PHP-FPM.
- Treba process manager (PM2, systemd) za auto-restart.
- Treba reverse proxy ispred (nginx) za SSL termination, load balancing.
- Memory leak detection važan (single process serves all requests).
- cPanel-style shared hosting često ne podržava long-running processes.
Tehnički zahtjevi production Node app
- Linux VPS (Ubuntu 22.04/24.04 preferiran).
- Node 20+ ili 22+ LTS.
- nginx kao reverse proxy.
- PM2 ili systemd za process management.
- SSL (Let's Encrypt).
- Database: ovisi o appu (Postgres, MongoDB, Redis).
Sizing
| App | vCPU | RAM | EUR/mj |
|---|---|---|---|
| Mali API (do 100 req/s) | 1-2 | 2 GB | ~10-25 |
| Mid SaaS (1000 req/s) | 4 | 8 GB | ~50-100 |
| Real-time chat (10k connections) | 4-8 | 16 GB | ~80-150 |
| High-throughput API (100k req/s) | 16+ | 32+ GB | ~250+ |
Production setup
# Install Node 20 LTS
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt install -y nodejs
# Install PM2
sudo npm install -g pm2
# Run app under PM2
pm2 start ecosystem.config.js
pm2 startup # auto-restart on reboot
pm2 save
nginx reverse proxy
server {
listen 443 ssl http2;
server_name api.example.com;
ssl_certificate /etc/letsencrypt/live/api.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/api.example.com/privkey.pem;
location / {
proxy_pass http://localhost:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
PM2 cluster mode
Node je single-threaded. Da iskoristiš sve CPU jezgre, koristi PM2 cluster mode:
// ecosystem.config.js
module.exports = {
apps: [{
name: 'api',
script: 'server.js',
instances: 'max', // koristi sve CPU cores
exec_mode: 'cluster'
}]
};
WebSocket support
Real-time apps (chat, live dashboards) trebaju WebSocket connection. nginx mora forward-at Upgrade headers (vidi config gore). Cloudflare ispred — uključi WebSocket support u dashboard-u.
Database opcije
- PostgreSQL — najpopularnija za Node prod (Prisma, TypeORM, Drizzle).
- MongoDB — za document-based use cases.
- Redis za cache, sessions, queue (BullMQ, Bee-Queue).
- SQLite za małe apps ili edge.
Alternative — managed Node platforms
- Vercel, Netlify Functions — serverless, perfect za API endpoint-e.
- Railway, Render, Fly.io — managed container hosting.
- Heroku — klasik.
Razlika: managed eliminira sysadmin overhead, ali skuplji na scale i manje kontrole.
WMD i Node.js hosting
WMD postavlja Node 20/22 LTS na dedicated VPS — PM2 cluster setup, nginx reverse proxy s WebSocket support, Let's Encrypt auto-renewal. Postgres ili MongoDB ovisno o appu, Redis za cache/queue. Deploy automation kroz GitHub Actions / Gitea Actions ili SSH-based deploy. JetBackup za database + uploads. Monitoring kroz PM2 dashboard + Sentry integration.
Paketi:
- Node Start (mali API): 1-2 vCPU, 2 GB RAM — od ~15 EUR/mj.
- Node Pro (SaaS, real-time): 4 vCPU, 8 GB RAM — od ~50 EUR/mj.
- Node Business (high-throughput): 8+ vCPU, 16+ GB RAM — od ~120 EUR/mj.
FAQ
Node 20 ili 22 LTS? 22 ako kreneš od nule (najduži support). 20 ako migriraš s 18.
PM2 ili systemd? PM2 ima bolji dev experience. systemd je system standard, manje moving parts. Oba radi.
Mogu li Node na cPanel-u? cPanel ima "Application Manager" za Node — radi za male apps, ali sysadmin VPS bolji za production.
Cluster mode mi crash-a — što? Provjeri shared state (sessions, in-memory cache) — mora bit u Redis-u, ne u memory svake instance.
Trebaš Node.js hosting ili deploy automation? WMD postavlja Node + PM2 + nginx + monitoring. Javi se preko kontakt forme.