GUIDE

Deployment

Keep the API running permanently, restart it when it crashes, and serve the docs on your machine.

Run in a terminal (simplest)

bash
cd /root/payment-api
python app.py

Fine for testing. The API stops when you close the terminal. For anything real, use pm2 below.

Run with pm2 (recommended)

pm2 keeps the API running in the background, restarts it if it crashes, and can start it automatically when the machine boots.

Install pm2 (once):

bash
npm install -g pm2

Start the API under pm2, using the project's virtualenv Python:

bash
cd /root/payment-api
pm2 start app.py --name payment-api \
  --interpreter venv/bin/python \
  --cwd /root/payment-api

Check it is up:

bash
pm2 status
# payment-api ... online
curl http://127.0.0.1:8000/health
# {"ok": true, "uptime": ...}
Why --interpreter matters
Without it pm2 runs app.py with the system Python, which may be missing dependencies. --interpreter venv/bin/python uses the virtualenv that has them.

Auto-start on boot

Two steps — generate the boot script, then save the process list:

bash
pm2 startup
# run the command it prints
pm2 save
# freezes the current process list so it restores on boot

After a reboot, the API comes back automatically. Verify with pm2 status.

pm2 cheatsheet

CommandWhat it does
pm2 statusList processes and their state
pm2 logs payment-apiFollow the API's log output
pm2 restart payment-apiRestart after a config change (e.g. editing .env)
pm2 stop payment-apiStop it without deleting the config
pm2 delete payment-apiRemove it from pm2 entirely
Port already in use?
If python app.py fails with "Address already in use" but pm2 status shows the API online, that is pm2 holding the port. Stop it (pm2 stop payment-api) before running a manual copy — or just use the pm2 one.

Serve the docs locally

The docs (docs/index.html and friends) are plain HTML — no build step. Serve them with nginx so programs on the machine can fetch them over HTTP:

bash
cat > /etc/nginx/sites-available/payment-api-docs.local <<'EOF'
server {
    listen 127.0.0.1:8081;
    server_name localhost;
    root /root/payment-api/docs;
    index index.html;
    location / { try_files $uri $uri/ =404; }
}
EOF
ln -s /etc/nginx/sites-available/payment-api-docs.local /etc/nginx/sites-enabled/
nginx -t && systemctl reload nginx

Then open http://127.0.0.1:8081/ in a browser on the machine.

Local only, by design
This binds to 127.0.0.1, so only programs on this machine can reach it. To serve the docs to other machines, you would add a domain and TLS — out of scope here.