Getting code from your laptop onto a live server that real users can reach involves more than just uploading files - this lesson covers the practical steps.
The basic deployment checklist
Before deploying: environment variables and secrets are configured on the server (never hardcoded), the database is migrated to match your code's expectations, dependencies are installed for production (not dev-only tools), and the app is configured to actually restart if it crashes.
A simple deployment via SSH
ssh user@your-server.com
cd /var/www/my-app
git pull origin main
npm install --production
pm2 restart my-app
pm2 is a process manager that keeps a Node.js app running in the background and restarts it automatically if it crashes - without it, closing your SSH session would kill the app.
Zero-downtime deploys
A naive deploy (stop the old version, start the new one) causes a brief outage. Better approaches run the new version alongside the old one, switch traffic over once it is confirmed healthy, then shut down the old version - most modern deployment platforms handle this automatically.
Environment-specific configuration
# .env.production (never committed to Git)
DATABASE_URL=mysql://user:pass@prod-db-host/app_db
API_KEY=live_key_here
Production and development should use different credentials and, often, different configuration entirely - this is exactly the same principle behind this site's own config/config.php staying out of version control and holding real values only on the live server.
Rolling back when something goes wrong
Always know how to revert to the previous working version quickly: git revert plus a redeploy, or restoring a specific previous container image, is far calmer to execute at 2am than trying to debug a broken production issue live while users are affected.