• About Us
  • Disclaimer
  • Indeks
Kebumen Update
No Result
View All Result
  • Web Hosting and Server Management
  • Monitoring & Maintenance
  • Security & Hardening
  • Panels & Tools
  • Cloud & DevOps
  • Tech
  • Web Hosting and Server Management
  • Monitoring & Maintenance
  • Security & Hardening
  • Panels & Tools
  • Cloud & DevOps
  • Tech
No Result
View All Result
Kebumen Update
No Result
View All Result
Home Web Hosting and Server Management

Deploying Node.js Apps on VPS: Complete Guide

awbsmed by awbsmed
April 12, 2025
in Web Hosting and Server Management
0
How To Install Node.js 20 LTS on Ubuntu 22.04|20.04|18.04 | by Navdeep  Sidana | Medium
ADVERTISEMENT

 

Deploying a Node.js application on a Virtual Private Server (VPS) gives you full control over your server environment, providing flexibility, scalability, and performance optimization. Whether you’re hosting a simple API or a complex backend system, managing the deployment yourself ensures that your application is secure, efficient, and running exactly how you intend it.

READ ALSO

Building a Secure FTP Server with vsftpd on Linux

Host a Website Using Apache or Nginx

This in-depth tutorial will walk you through every step of deploying a Node.js app on a VPS, from selecting a server to setting up security and deploying your code. It’s tailored for beginners and developers looking to transition from local development to real-world hosting.

ADVERTISEMENT

A. Why Choose a VPS for Node.js?

There are several compelling reasons to deploy your Node.js app on a VPS rather than on shared hosting:

A. Performance – With dedicated resources, you won’t be slowed down by other users on the same server.

B. Full Control – Root access means you can install custom software and configure the environment to your liking.

C. Scalability – As your app grows, you can upgrade your VPS resources with minimal hassle.

D. Better Security – VPS gives you the ability to implement and customize your own security policies.


B. Prerequisites Before Deployment

Before jumping into deployment, make sure you have the following:

A. A VPS with root or sudo access (Ubuntu 22.04 is recommended for this guide).
B. A domain name (optional, but highly recommended).
C. Node.js application ready for deployment.
D. Basic familiarity with using SSH and the Linux command line.


C. Step-by-Step Deployment Process

Let’s break the process into detailed, manageable steps.


1. Connect to Your VPS

You’ll first need to connect to your server using SSH:

bash
ssh username@your_server_ip

Replace username with your VPS user (typically root or a sudo user) and your_server_ip with your server’s actual IP address.


2. Update and Secure Your Server

Start by updating the system packages:

bash
sudo apt update && sudo apt upgrade -y

It’s also wise to set up a firewall using UFW (Uncomplicated Firewall):

bash
sudo ufw allow OpenSSH
sudo ufw enable

This will allow only SSH access by default. You can open additional ports later as needed.


3. Install Node.js and npm

Install Node.js using the NodeSource repository for the latest stable version:

bash
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -
sudo apt install -y nodejs

Verify installation:

bash
node -v
npm -v

4. Install Git

Git is used for cloning your app from a repository like GitHub:

bash
sudo apt install git -y

Clone your project:

bash
git clone https://github.com/yourusername/your-node-app.git
cd your-node-app

5. Install Application Dependencies

Navigate into your app’s root directory and install the dependencies:

bash
npm install

Make sure your app has a valid package.json file. You can run the application locally to test:

bash
node app.js

Or whatever file starts your app (server.js, index.js, etc.)


6. Use PM2 to Manage Your App

PM2 is a production-ready process manager for Node.js applications:

bash
sudo npm install pm2 -g

Start your app using PM2:

bash
pm2 start app.js

Set PM2 to start your app on server boot:

bash
pm2 startup
pm2 save

You can monitor your app with:

bash
pm2 list
pm2 logs

7. Install and Configure Nginx as a Reverse Proxy

Installing Nginx will help manage traffic and provide better performance:

bash
sudo apt install nginx -y

Configure a reverse proxy so Nginx forwards requests to your Node.js app:

bash
sudo nano /etc/nginx/sites-available/yourdomain.com

Paste the following configuration:

nginx
server {
listen 80;
server_name yourdomain.com www.yourdomain.com;
location / {
proxy_pass http://localhost:3000; # Port where Node app is running
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection ‘upgrade’;
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}

Enable the configuration and restart Nginx:

bash
sudo ln -s /etc/nginx/sites-available/yourdomain.com /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx

8. Optional: Secure with SSL Using Let’s Encrypt

Install Certbot:

bash
sudo apt install certbot python3-certbot-nginx -y

Run Certbot to configure SSL:

bash
sudo certbot --nginx

Follow the prompts to enable HTTPS on your domain.

Test renewal:

bash
sudo certbot renew --dry-run

9. Set Up a Custom Domain (Optional)

If you want to use a custom domain:

A. Go to your domain registrar’s DNS management.
B. Point an A record to your VPS’s IP address.
C. Wait for DNS propagation (can take up to 48 hours).

Once DNS is configured, Nginx and SSL will handle the rest.


10. Automate Deployment (Optional)

You can use tools like GitHub Actions or a CI/CD pipeline to automate deployment steps:

A. Pull latest code
B. Install dependencies
C. Restart PM2 process

This keeps your application always up to date.


D. Common Issues and How to Fix Them

A. App crashes after deployment – Use pm2 logs to check the issue.
B. Port conflicts – Ensure only one app is listening on a specific port.
C. Nginx 502 Bad Gateway – Verify the app is running on the correct port and Nginx is forwarding correctly.
D. Firewall blocking traffic – Use ufw allow 'Nginx Full' to open necessary ports.


E. Maintaining and Monitoring Your VPS

Routine maintenance ensures your server stays healthy:

A. Regularly update the OS and packages:

bash
sudo apt update && sudo apt upgrade

B. Use monitoring tools like Netdata, htop, or server dashboards.
C. Schedule automatic backups or use snapshot features provided by your VPS host.
D. Harden SSH access by changing the default port or using key authentication.

Tags: nginx reverse proxynode.jsubuntu serverVPS deployment
ADVERTISEMENT

Related Posts

Install and configure an FTP Server in Linux CentOS 7.x with VSFTPD
Web Hosting and Server Management

Building a Secure FTP Server with vsftpd on Linux

April 12, 2025
Install an NGINX web server on Ubuntu and create a website! | by Terminals  & Coffee | Medium
Web Hosting and Server Management

Host a Website Using Apache or Nginx

April 12, 2025
How to Install LAMP on Ubuntu 20.04 with Screenshots - Pentarock  Technologies
Web Hosting and Server Management

LAMP Stack Installation on Ubuntu 22.04

April 12, 2025
How to Set up a VPS Hosting Environment from Scratch? -
Web Hosting and Server Management

How to Set Up a VPS from Scratch

April 12, 2025
Next Post
Install an NGINX web server on Ubuntu and create a website! | by Terminals  & Coffee | Medium

Host a Website Using Apache or Nginx

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Hybrid Cloud Reigns: The Smart IT Strategy

Hybrid Cloud Reigns: The Smart IT Strategy

by Salsabilla Yasmeen Yunanta
June 26, 2025
0

In the intricate landscape of modern enterprise IT, the concept of a singular, all-encompassing solution is increasingly a relic of...

NVMe Storage Transforms: The Data Speed Revolution

NVMe Storage Transforms: The Data Speed Revolution

by Salsabilla Yasmeen Yunanta
June 26, 2025
0

In the lightning-fast world of modern computing, where every millisecond counts, the storage subsystem has long been a bottleneck. Traditional...

Best Server Providers for 2025 - Server

Top Server Providers for 2025

by awbsmed
May 17, 2025
0

In the rapidly evolving digital landscape of 2025, selecting the right server provider is crucial for businesses and individuals alike....

Edge Computing Transforms Real-Time Data Processing

Edge Computing Transforms Real-Time Data Processing

by awbsmed
May 16, 2025
0

In an era defined by instantaneous insights and ultra‑low latencies, edge computing has emerged as a transformative force reshaping how...

Kebumen Update

KebumenUpdate.com diterbitkan oleh PT BUMI MEDIA PUBLISHING dengan sertifikat pendirian Kementerian Hukum dan Hak Asasi Manusia Republik Indonesia Nomor: AHU-012340.AH.01.30.Tahun 2022

  • About Us
  • Editor
  • Code of Ethics
  • Privacy Policy
  • Cyber Media Guidelines

Copyright © 2025 Kebumen Update. All Right Reserved

No Result
View All Result
  • Homepages
    • Home Page 1
    • Home Page 2
  • Tech

Copyright © 2025 Kebumen Update. All Right Reserved