We earn commissions when you shop through the links below.
If you’ve been searching for a straightforward walkthrough on how to deploy Node.js app on Hostinger, you’re in the right place. Hostinger’s VPS plans are surprisingly capable for Node.js workloads, and the price-to-performance ratio is hard to beat for indie developers and small teams. In this guide, I’ll walk you through everything from initial server setup to keeping your app alive with PM2.
Why Hostinger for Node.js?
Hostinger VPS plans start cheap, include full root access, and come with a reasonably fast provisioning time. You get a real Linux environment, so you can run Node.js exactly as you would on any other VPS. It’s not a platform-as-a-service with magic buttons — you manage the server yourself, which means more control and no vendor lock-in.
That said, if you want zero server management, something like Railway might suit you better. But if you’re comfortable with SSH and want a cost-effective long-term host, Hostinger is a solid choice.
Prerequisites
- A Hostinger VPS plan (KVM 1 or above recommended)
- A Node.js app ready to deploy (Express, Fastify, or anything else)
- Basic familiarity with the terminal and SSH
- A domain name pointed to your server’s IP (optional but recommended)
Step 1: Connect to Your VPS via SSH
Once your VPS is provisioned, Hostinger will give you an IP address, a root username, and a password (or SSH key option). Open your terminal and connect:
ssh root@YOUR_SERVER_IPIf you set up an SSH key during provisioning, it’ll connect without a password prompt. I strongly recommend using SSH keys over passwords for security.
Step 2: Update the Server and Install Node.js
Always update packages first on a fresh VPS:
apt update && apt upgrade -yNext, install Node.js. I recommend using NodeSource to get a specific version rather than relying on the outdated package in Ubuntu’s default repos:
# Install Node.js 20.x (LTS)
curl -fsSL https://deb.nodesource.com/setup_20.x | bash -
apt install -y nodejs
# Verify installation
node -v
npm -vYou should see version numbers confirming both are installed correctly.
Step 3: Upload Your Application
There are two common ways to get your code onto the server:
Option A: Clone from Git (Recommended)
# Install git if not present
apt install -y git
# Clone your repository
cd /var/www
git clone https://github.com/yourusername/your-app.git
cd your-appOption B: SCP from Local Machine
scp -r ./your-app root@YOUR_SERVER_IP:/var/www/your-appOnce the code is on the server, install dependencies:
cd /var/www/your-app
npm install --productionStep 4: Configure Environment Variables
Never hardcode secrets. Create a .env file on the server directly:
nano /var/www/your-app/.envAdd your variables:
NODE_ENV=production
PORT=3000
DATABASE_URL=your_database_connection_string
JWT_SECRET=your_secret_keySave and exit with Ctrl+X, then Y, then Enter.
Step 5: Install and Configure PM2
Running your app with node server.js directly means it dies the moment you close the SSH session. PM2 is the standard process manager for Node.js in production — it keeps your app alive, restarts it on crashes, and can boot it on server startup.
npm install -g pm2Start your app:
pm2 start /var/www/your-app/server.js --name "my-app"If your entry point is different (like index.js or you use a start script), adjust accordingly. You can also use an ecosystem file for more control:
# ecosystem.config.js
module.exports = {
apps: [{
name: 'my-app',
script: './server.js',
instances: 'max',
exec_mode: 'cluster',
env: {
NODE_ENV: 'production',
PORT: 3000
}
}]
};Then start with:
pm2 start ecosystem.config.jsMake PM2 restart your app automatically on server reboot:
pm2 startup
pm2 savePM2 will print a command for you to run — copy and execute it. Then save the current process list with pm2 save.
Step 6: Set Up Nginx as a Reverse Proxy
You don’t want to expose port 3000 to the world. Use Nginx to proxy traffic from port 80 (HTTP) or 443 (HTTPS) to your Node.js process.
apt install -y nginxCreate a new Nginx config for your app:
nano /etc/nginx/sites-available/my-appserver {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost: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-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_cache_bypass $http_upgrade;
}
}Enable the site and restart Nginx:
ln -s /etc/nginx/sites-available/my-app /etc/nginx/sites-enabled/
nginx -t
systemctl restart nginxStep 7: Enable HTTPS with Let’s Encrypt
No production app should run without SSL. Certbot makes this trivial:
apt install -y certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com -d www.yourdomain.comFollow the prompts. Certbot will automatically modify your Nginx config to handle HTTPS and set up auto-renewal. Once done, your app is live at https://yourdomain.com.
Step 8: Useful PM2 Commands
Here are the PM2 commands you’ll use most often once your app is running:
# Check app status
pm2 status
# View logs
pm2 logs my-app
# Restart after code update
pm2 restart my-app
# Monitor CPU and memory
pm2 monitDeploying Updates
Once your app is live, deploying updates is straightforward:
cd /var/www/your-app
git pull origin main
npm install --production
pm2 restart my-appYou can automate this with a simple shell script or hook it into a CI/CD pipeline using GitHub Actions if you want zero-touch deploys.
Common Issues and Fixes
Port already in use: Run lsof -i :3000 to find what’s using the port, then kill the process or change your app’s port.
App not accessible: Check that your Hostinger firewall rules allow ports 80 and 443. In the hPanel, look for the firewall or security settings.
Nginx 502 Bad Gateway: Your Node.js app probably isn’t running. Check with pm2 status and view logs with pm2 logs.
Final Thoughts
Knowing how to deploy Node.js app on Hostinger is a genuinely useful skill — it gives you a cost-effective, flexible production environment without the complexity of Kubernetes or the cost of managed platforms. The combination of Nginx, PM2, and Let’s Encrypt covers the vast majority of production use cases for indie apps and internal tools.
If you want to go deeper on Node.js backend development and DevOps fundamentals, Udemy has solid courses covering everything from Express architecture to full deployment pipelines at reasonable prices.
Once you’ve got the basics down, you can extend this setup with database connections, background workers, and automated deployments. But for most projects, what you’ve set up here is production-ready.