How to Deploy a Node.js App on a Hostinger VPS (Step-by-Step for Beginners)

Article4 min read👁️ 250
Dharmendra Singh Yadav

Dharmendra Singh Yadav

Founder, Dharmsy Innovations

How to Deploy a Node.js App on a Hostinger VPS (Step-by-Step for Beginners)

If you’ve built a Node.js app (like an API, backend, or dashboard) and want it to run live on your own Hostinger VPS, this guide walks you through everything — from setting up the server to making your domain live with SSL (https).

Let’s get started 👇

🖥️ Step 1: Connect to Your VPS

Once you buy your VPS, Hostinger gives you:

  1. A public IP address
  2. A root username
  3. A password

On your laptop or desktop, open Terminal (Mac/Linux) or PowerShell (Windows) and connect:

ssh root@YOUR_SERVER_IP

Example:

That’s you entering your new remote computer 🚀

Step 2: Create a New User (for safety)

It’s best not to work directly as “root”. Create a normal user:

adduser deploy
usermod -aG sudo deploy

Now you can log in using that user:

ssh deploy@YOUR_SERVER_IP

This keeps your server more secure.

⚙️ Step 3: Install Node.js and PM2

We’ll use nvm (Node Version Manager) — it’s the safest way to install Node.js.

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
source ~/.bashrc
nvm install --lts

Now Node.js is installed. Check it:


node -v
npm -v

Then install PM2 — a tool that keeps your Node.js app running forever, even if the server restarts.

npm install -g pm2

Step 4: Get Your Project on the Server

You can either upload files via Git, FTP, or ZIP.

Easiest way:

mkdir apps && cd apps
git clone https://github.com/YOUR_USERNAME/YOUR_PROJECT.git
cd YOUR_PROJECT
npm install

If your project uses environment variables (like database URL, API keys), create a .env file:

PORT=4001
MONGO_URL=mongodb+srv://your_database_url
JWT_SECRET=your_secret

Step 5: Test if Your App Works

Before setting up anything fancy, make sure your app runs:

node server.js

(Replace server.js with your app’s main file if it’s different.)

If it prints something like Server running on port 4001, that’s great! 🎉

Press Ctrl + C to stop it.

Step 6: Keep It Running Forever (Using PM2)

Now we’ll use PM2 to keep your app alive all the time:

pm2 start server.js --name myapp
pm2 save
pm2 startup

This means:

  1. Your app will automatically restart if it crashes.
  2. It will even start after your server reboots.

To check:

pm2 status
pm2 logs myapp

Step 7: Install Nginx (To Serve the App on a Domain)

Nginx acts like a “traffic manager” for your server — it receives all requests (like from api.dharmsy.com) and forwards them to your Node app running on port 4001.

Install Nginx:

sudo apt install nginx -y

Then make a config file for your domain:

sudo nano /etc/nginx/sites-available/myapp

Paste this inside (change the domain name and port if needed):

server {
listen 80;
server_name api.secure.com;

location / {
proxy_pass http://127.0.0.1:4001;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}

Now activate the config:

sudo ln -s /etc/nginx/sites-available/myapp /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

🔒 Step 8: Add Free SSL (HTTPS) with Let’s Encrypt

Let’s Encrypt gives you free HTTPS for your domain.

sudo apt install certbot python3-certbot-nginx -y
sudo certbot --nginx -d api.secure.com

Follow the on-screen steps and choose the option to redirect HTTP to HTTPS.


Now your site is secure:

https://api.secure.com works!

Step 9: Update Your App Without Downtime

When you push new code to GitHub, you can update it easily:

cd ~/apps/YOUR_PROJECT
git pull
npm install
pm2 reload myapp

That’s it — no downtime, your API updates instantly 🚀

Step 10: Monitor and Manage

See if everything’s okay:

pm2 status
pm2 logs
pm2 monit

You’ll see CPU usage, memory, uptime, and logs.

Optional — Simple Auto Deploy Script

You can create a small script to update everything in one command:

nano ~/deploy-myapp.sh

Paste:-

#!/bin/bash
cd ~/apps/YOUR_PROJECT
git pull
npm install
pm2 reload myapp

Then make it executable:

chmod +x ~/deploy-myapp.sh

💡 Bonus Tips

  1. Use one VPS to host multiple apps (just change ports & Nginx configs)
  2. Use UFW firewall to block unwanted ports:
sudo ufw allow OpenSSH
sudo ufw allow http
sudo ufw allow https
sudo ufw enable
  1. Always run pm2 save after starting your apps
  2. You can check if SSL auto-renew works:
systemctl status certbot.timer

Work with Dharmsy Innovations

Turn Your SaaS or App Idea Into a Real Product — Faster & Affordable

Dharmsy Innovations helps founders and businesses turn ideas into production-ready products — from MVP and prototypes to scalable platforms in web, mobile, and AI.

No sales pressure — just honest guidance on cost, timeline & tech stack.