Running node index.js directly is fine for local development, but production apps need a process manager. This tutorial covers PM2.
Step 1 — Install PM2
npm install -g pm2
Step 2 — Start Your App
pm2 start index.js --name my-app
Step 3 — Useful Commands
pm2 list
pm2 logs my-app
pm2 restart my-app
pm2 stop my-app
Step 4 — Auto-Restart on Server Reboot
pm2 startup
pm2 save
Why PM2?
PM2 automatically restarts your app if it crashes, manages logs, and supports zero-downtime reloads — all without extra infrastructure.