WebSockets keep a bidirectional connection (chats, dashboards, games). Here: a minimal Node server plus Nginx in front.
Steps
Install Node.js LTS if needed and create a project:
mkdir -p ~/ws-demo && cd ~/ws-demonpm init -y && npm install wsCreate
server.jswith awsserver on port 8080 and start it (or under screen/tmux):node server.jsIn Nginx, proxy with connection upgrade (example location):
# location /ws/ { proxy_pass http://127.0.0.1:8080/; proxy_http_version 1.1;# proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; }sudo nginx -t && sudo systemctl reload nginxTest from a browser or client:
wss://YOUR_DOMAIN/ws/(with SSL).
Tips
- Bind to 127.0.0.1 only and let Nginx/Certbot handle TLS.
- In production use a process manager (systemd or PM2), not a bare Node in SSH.
ext step
VPS ready for realtime APIs: Deploy your Cloud VPS.