How to Deploy Python and Node.js Apps on VPS
Choose a runtime
Section titled “Choose a runtime”Python suits API backends, automation and data processing. Node.js suits JavaScript servers and real-time applications. For production, run each service under a non-root account, supervise it with systemd and expose it through Nginx.
This walkthrough assumes Ubuntu 24.04, SSH access and a DNS name such as app.example.com. Replace examples with your own domain.
1. Prepare the server
Section titled “1. Prepare the server”sudo apt updatesudo apt install -y python3 python3-venv python3-pip nginx nodejs npmpython3 --versionnode --versionCheck that your installed Node.js release is still supported; Ubuntu’s stock version may not be the latest LTS. Use the official Node.js distributions for a newer supported release when necessary.
2. Deploy a Python API (FastAPI)
Section titled “2. Deploy a Python API (FastAPI)”sudo useradd --system --create-home --shell /usr/sbin/nologin appsvc || truesudo mkdir -p /opt/py-apisudo chown appsvc:appsvc /opt/py-apisudo -u appsvc python3 -m venv /opt/py-api/.venvsudo -u appsvc /opt/py-api/.venv/bin/pip install fastapi uvicornsudo tee /opt/py-api/main.py >/dev/null <<'EOF'from fastapi import FastAPIapp = FastAPI()@app.get("/health")def health(): return {"status": "ok"}EOFsudo chown appsvc:appsvc /opt/py-api/main.pyCreate /etc/systemd/system/py-api.service:
[Unit]Description=Python FastAPI serviceAfter=network-online.target
[Service]User=appsvcWorkingDirectory=/opt/py-apiExecStart=/opt/py-api/.venv/bin/uvicorn main:app --host 127.0.0.1 --port 8001Restart=on-failureNoNewPrivileges=true
[Install]WantedBy=multi-user.targetThen run:
sudo systemctl daemon-reloadsudo systemctl enable --now py-apicurl http://127.0.0.1:8001/health3. Deploy a Node.js application
Section titled “3. Deploy a Node.js application”Create an isolated app directory and a small HTTP server:
sudo mkdir -p /opt/node-apisudo tee /opt/node-api/server.mjs >/dev/null <<'EOF'import http from 'node:http';http.createServer((_req, res) => { res.writeHead(200, {'content-type': 'application/json'}); res.end(JSON.stringify({status: 'ok'}));}).listen(8002, '127.0.0.1');EOFsudo chown -R appsvc:appsvc /opt/node-apiCreate /etc/systemd/system/node-api.service:
[Unit]Description=Node API serviceAfter=network-online.target
[Service]User=appsvcWorkingDirectory=/opt/node-apiExecStart=/usr/bin/node /opt/node-api/server.mjsRestart=on-failureNoNewPrivileges=true
[Install]WantedBy=multi-user.targetIf Node was installed outside /usr/bin, adjust ExecStart after checking command -v node. Start it with systemctl daemon-reload and systemctl enable --now node-api.
4. Route traffic through Nginx
Section titled “4. Route traffic through Nginx”For the Python API, create a site pointing to port 8001 (use 8002 for the Node example):
server { listen 80; server_name app.example.com; location / { proxy_pass http://127.0.0.1:8001; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; }}Enable the site, run sudo nginx -t, reload Nginx, then issue a TLS certificate using Certbot after DNS is configured. Do not serve production APIs permanently over plain HTTP.
5. Verify and maintain
Section titled “5. Verify and maintain”sudo systemctl status py-apisudo journalctl -u py-api -n 30 --no-pagercurl -I https://app.example.com/healthStore credentials in root-readable environment files, restrict permissions, monitor memory and CPU, and back up application state. Avoid exposing development/debug modes to the internet.
Need a VPS for this project? Compare ProstoHosting VPS plans.