How to deploy a Node.js app to production
Updated 7/20/2026
Running node app.js in a terminal does not keep the app alive after you disconnect. Here is how to deploy it properly, with auto-restart and an HTTPS domain.
1. Install Node.js
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt-get install -y nodejs
2. Run the app with PM2
PM2 keeps the app running and restarts it if it stops:
npm install -g pm2
cd /var/www/app
pm2 start app.js --name my-app
pm2 startup
pm2 save
3. Put Nginx in front
The app listens on an internal port (e.g. 3000); Nginx receives public traffic. See How to set up Nginx as a reverse proxy.
4. Add HTTPS
See Free SSL certificate with Let's Encrypt.
Useful PM2 commands
pm2 list
pm2 logs my-app
pm2 restart my-appPut this guide into practice on your own VPS
EU cloud servers, billed hourly, ready in minutes, with one-click installs for dozens of apps.
See pricingRelated tutorials
How to optimize Nginx performance: gzip, cache and HTTP/2
Make your site faster with gzip compression, static file caching and HTTP/2, a few lines of config.
Updated 7/20/2026Web serversHow to install phpMyAdmin to manage MySQL from the browser
Manage your MySQL databases from a web interface with phpMyAdmin, installed and secured correctly.
Updated 7/20/2026Web serversHow to host a static site or a React/Vue app
Publish a static site or a React/Vue build on Nginx, with correct routing for single-page apps.
Updated 7/20/2026