Deploy apps · 15 min
Deploy a Node.js app with PM2
Run a Node.js app on your server and keep it running after crashes and reboots.
PM2 keeps your Node.js app running: it restarts it if it crashes and starts it again after a reboot.
1. Install Node.js and PM2
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
sudo apt install -y nodejs git
sudo npm install -g pm22. Get your code onto the server
cd /opt
sudo git clone https://github.com/you/your-app.git
sudo chown -R $USER:$USER your-app
cd your-app
npm ci3. Start it with PM2
pm2 start npm --name my-app -- start
pm2 save
pm2 startuppm2 startup prints one more command. Copy and run it, so your app starts after a reboot.
4. Make it reachable
Your app probably listens on a port like 3000. Either:
- open that port in the firewall for quick testing, or
- better: put it behind Nginx on port 80/443 with a domain and HTTPS. See Free HTTPS with Let's Encrypt.
Everyday commands
pm2 status # what's running
pm2 logs my-app # see the output
pm2 restart my-appUpdating your app
cd /opt/your-app && git pull && npm ci && pm2 restart my-appStuck? Contact us or open a support ticket from your panel.