You have created an API for a mobile application, an online booking service, or a small online store that works perfectly on your computer. However, no one else can see it, and every time you turn off your laptop, the software stops working. For others to use it, it needs a server that runs 24/7, has a static IP address, a domain, and HTTPS. To save you time, we have prepared a step-by-step guide on how to deploy a Node.js application on a VPS: from an empty server to a working application at your address.

What to prepare before deployment
First, you need to rent the virtual server itself. When renting a VPS, Ubuntu 24.04 is installed by default, which is what all the commands in this article are written for. For a small application, 2 GB of RAM will be sufficient; if a database will be running alongside, 4 GB; for heavy sites on Next.js, 8 GB.
Immediately add an A record in the domain management panel with the server's IP address, which you will receive via email after activation. DNS updates take time, so while you are setting up the server, the record will have time to propagate. Upload the application code to GitHub along with the package-lock.json file, which contains the exact versions of the libraries.
Along with the IP address, you will receive the root user password via email. Connect to the server via SSH using the command, which is the same on Windows 10/11, macOS, and Linux:
ssh root@server-IP-address
Next, you need to create a new user and give them permission to use sudo (the prefix that enables administrator rights for a single command):
adduser deploy
usermod -aG sudo deploy
After that, connect as ssh deploy@server-IP-address and continue working under this user.
Also read: What is SSH and the main ways to work with it
How to install Node.js on the server
There is nothing from your laptop on the VPS, so Node.js needs to be installed anew, and it should be the same version that you developed the application with. Otherwise, some code or libraries may not run.
So first check the version on your computer with the command node -v. For internet work, the official documentation recommends only LTS versions. According to the release schedule, this is currently Node.js 22, 24, and 26 (LTS status from October 28, 2026). If you have 18 or 20, first update Node.js on your computer and check if your project works.
Important! Do not use the command sudo apt install nodejs. In Ubuntu 24.04, it will install Node.js 18, which is no longer supported. It is better to get the required version from the NodeSource repository.
To install version 24, use the command:
curl -fsSL https://deb.nodesource.com/setup_24.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
sudo apt install -y nodejs
node -v
The last command should show the same version as on your computer. Along with Node.js, npm is installed, and security updates will come with sudo apt upgrade.
How to run a Node.js application on VPS
First, copy the code to the server and install the libraries:
git clone https://github.com/your-account/myapp.git
cd myapp
npm ci --omit=dev
The npm ci command installs libraries according to the list in package-lock.json, and --omit=dev skips development tools. If the application needs to be built, for example, on TypeScript or Next.js, instead run npm ci and npm run build.
Passwords and API keys are stored in the .env file, which does not get into Git, so create it on the server with the command nano .env and write the same lines as locally. Save the file with the combination Ctrl+O and Enter, exit with Ctrl+X, and restrict access to others with the command chmod 600 .env.
Next, check the address where your project is running. The application should accept requests only from within the server, while visitors will be allowed through Nginx, which we will configure next. For this, the address in the code should be set to 127.0.0.1. For the Express framework, it looks like this:
app.listen(3000, '127.0.0.1');
If you run the application with the usual command node server.js, it will stop along with the SSH connection or after the first error. Therefore, use the process manager PM2, which restarts the application after a crash and server reboot:
sudo npm install -g pm2
pm2 start server.js --name myapp --node-args="--env-file=.env"
pm2 startup
pm2 save
Instead of server.js, specify the main file of the application. The --node-args parameter passes the --env-file flag so that the application receives secrets (DB passwords, payment system keys) from .env. The pm2 startup command will output another command that needs to be copied and executed to enable auto-start. Finally, check the result with pm2 status: myapp should be online.

How to open the application for visitors through Nginx
To allow everyone to see and use your application, use Nginx—a server that accepts visitors on ports 80 and 443 and forwards requests to the application. Install it and create a configuration file:
sudo apt install -y nginx
sudo nano /etc/nginx/sites-available/myapp
Insert the following text into it, replacing example.com with your domain:
server {
listen 80;
server_name example.com www.example.com;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
The proxy_pass line forwards requests to the application on port 3000, and Upgrade and Connection are needed for WebSocket, which chat and real-time notifications rely on. Enable the configuration and check it with the command:
sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx
If nginx -t reports no errors, open http://your-domain.com in a browser, where your application should appear. For each subsequent project on this server, create a separate file with your domain and port.
How to connect free HTTPS
The certificate for HTTPS is issued for free by Let’s Encrypt. On regular hosting, it is issued and renewed by the provider, while on VPS, this work is done by Certbot. Developers recommend installing it via snap:
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/local/bin/certbot
sudo certbot --nginx -d example.com -d www.example.com
sudo certbot renew --dry-run
Certbot will ask for an email for notifications and will configure Nginx for https://. The last command checks for auto-renewal: if there are no errors, the certificate will renew itself.
Important! Let’s Encrypt checks the domain via port 80. If Certbot gives an error, check that the A record already points to the server's IP and that port 80 is open in the Firewall in the VPS control panel.
How to close unnecessary ports
HTTPS protects data on the way to the server, while the firewall protects the server itself. It closes all ports except the necessary ones: 22 for SSH, 80 and 443 for the site.
To avoid losing access via SSH, enable the built-in UFW firewall in Ubuntu in the following order:
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable
The external Firewall in the VPS-UP control panel filters traffic before it reaches the server and does not conflict with UFW. Open the same three ports in it to get two levels of protection.
Also read: DDoS attack: methods of protecting servers and websites
How to update a Node.js application after launch
You continue to work on the application on your computer, and the server does not update anything by itself. A new version reaches users only when you deploy it:
-
Make changes to the code and test them on localhost.
-
Push the changes to GitHub with the command git push.
-
Connect to the server via SSH and navigate to the project folder.
-
Download the new version of the code with the command git pull.
-
Update the libraries with the command npm ci --omit=dev.
-
Restart the application with the command pm2 reload myapp.
If the new version does not start, the command pm2 logs myapp will show the error. To revert to the working version, use git revert HEAD on your computer: push the result to GitHub and repeat steps 3-6. Before making changes to the server itself, such as updating Node.js or Ubuntu, create a Snapshot in the control panel to revert the VPS to a saved state if needed.
Finally, reboot the server with the command sudo reboot and after a minute, open the site from your phone. If the application started by itself and opens via HTTPS, it is ready for real users. And when the load exceeds the capabilities of the VPS, you can switch to a dedicated server and repeat the same steps.
