Net2Secure: A Leading Data Center Service Provider in India
Grab the Freedom Deal: ₹2,000 FREE Cloud Credits! Claim Now
Grab the Freedom Deal: ₹2,000 FREE Cloud Credits! Claim Now
Grab the Freedom Deal: ₹2,000 FREE Cloud Credits! Claim Now
Grab the Freedom Deal: ₹1,000 FREE Cloud Credits! Claim Now
+91 9953046498 sales@net2secure.com Support Login | Register

⮚ KB ⮚ How to Deploy Node.js on Ubuntu VPS: Production Guide 2026

How to Deploy Node.js on Ubuntu VPS: Production Guide 2026


Deploying Node.js on an Ubuntu VPS gives developers control over the Node.js version, application process, Nginx configuration, HTTPS, firewall rules and server resources. This guide walks through a production-oriented setup using a supported Node.js LTS release, a non-root user, systemd or PM2, Nginx, Certbot and Ubuntu security controls.

Quick Answer: How Do You Deploy Node.js on an Ubuntu VPS?

To deploy a Node.js application on Ubuntu VPS, create a non-root administrative user, update Ubuntu, install a supported Node.js LTS version, deploy the application with npm, run it persistently using systemd or PM2, place Nginx in front of the Node.js process, allow only required firewall ports and enable HTTPS with a trusted TLS certificate. Keep the Node.js application bound to localhost when Nginx is handling public traffic.

Why Use an Ubuntu VPS for Node.js Hosting?

A Node.js application often needs more control than basic shared hosting provides. With an Ubuntu VPS hosting environment, you can manage the operating system, Node.js runtime, packages, reverse proxy, firewall and application services according to your workload.

This makes an Ubuntu VPS useful for Node.js APIs, backend services, Express applications, real-time applications, SaaS platforms and development or staging environments. The resources required depend on application architecture, concurrent traffic, database activity, background tasks and other services running on the server.

Component Purpose Recommended Approach
Ubuntu Server operating system Use a currently supported Ubuntu LTS release
Node.js JavaScript runtime Use a currently supported LTS release
npm Dependency management Use a lockfile and reproducible production installs
systemd or PM2 Keeps the application running Choose one process-management approach
Nginx Public web server and reverse proxy Proxy requests to Node.js on localhost
Certbot TLS certificate automation Configure HTTPS after DNS points to the VPS
UFW Host firewall Permit SSH, HTTP and HTTPS only as required

Prerequisites Before Deploying Node.js

You should have:

  • An Ubuntu VPS with SSH access.
  • A domain or subdomain if the application will use HTTPS.
  • A DNS A or AAAA record pointing to the VPS.
  • Your Node.js application source code or Git repository.
  • Sudo access for server administration.

If you are still selecting infrastructure, compare VPS hosting, Linux VPS hosting and Ubuntu VPS hosting based on the CPU, memory, storage, network and management requirements of your Node.js application.

Step-by-Step: Deploy Node.js on Ubuntu VPS

Step 1: Connect to Your Ubuntu VPS

Connect over SSH using the IP address or hostname supplied for your VPS:

ssh root@YOUR_SERVER_IP
Security note: Avoid operating the application permanently as root. Use root only for initial administration when necessary, then deploy and run the Node.js application under an unprivileged account.

Step 2: Update Ubuntu Packages

Refresh package metadata and install available package updates before configuring the application stack.

sudo apt update
sudo apt upgrade -y

If the update indicates that a reboot is required, plan an appropriate maintenance window and reboot before continuing.

Step 3: Create a Non-Root Deployment User

Create a dedicated administrative account:

sudo adduser deploy
sudo usermod -aG sudo deploy

Configure your SSH public key for the deploy account and verify that you can log in successfully before changing any SSH authentication settings.

ssh deploy@YOUR_SERVER_IP

Running application processes as an unprivileged user limits the privileges available to the application if the process is compromised.

Step 4: Install the Current Supported Node.js LTS Release

At the time this article was technically verified, Node.js 26.x is an LTS release. Because Node.js versions change over time, check the official Node.js release page before deploying a new production server.

Node.js lists version-manager installation methods such as NVM among its recommended installation approaches. For the version current at this article's verification date:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.7/install.sh | bash

. "$HOME/.nvm/nvm.sh"

nvm install 26
nvm alias default 26

node -v
npm -v
Production maintenance: Do not assume that Node.js 26 will always be the recommended version. Check the official Node.js release schedule when creating or rebuilding a VPS, and plan upgrades before your installed release reaches end of life.

Step 5: Create or Upload the Node.js Application

Create an application directory:

mkdir -p ~/apps/nodeapp
cd ~/apps/nodeapp

If you already have an application, clone or securely transfer it into this directory. For a minimal demonstration:

npm init -y
npm install express

Create app.js:

const express = require('express');

const app = express();
const PORT = process.env.PORT || 3000;
const HOST = '127.0.0.1';

app.get('/', (req, res) => {
  res.send('Node.js application is running on Ubuntu VPS.');
});

app.get('/health', (req, res) => {
  res.status(200).json({ status: 'ok' });
});

const server = app.listen(PORT, HOST, () => {
  console.log(`Node.js listening on http://${HOST}:${PORT}`);
});

function shutdown(signal) {
  console.log(`${signal} received. Closing HTTP server...`);
  server.close(() => {
    process.exit(0);
  });
}

process.on('SIGTERM', () => shutdown('SIGTERM'));
process.on('SIGINT', () => shutdown('SIGINT'));

Test the application:

node app.js

In another SSH session:

curl http://127.0.0.1:3000/health

You should receive a response similar to:

{"status":"ok"}

Stop the foreground process with Ctrl+C.

Step 6: Manage Production Environment Variables

Avoid placing database passwords, API keys and other secrets directly in source code or committing them to Git.

Create an environment file:

nano ~/apps/nodeapp/.env

Example:

NODE_ENV=production
PORT=3000

Restrict access to the file:

chmod 600 ~/apps/nodeapp/.env

Production secrets should be managed according to your organization's secrets-management and access-control policies.

Run Node.js Continuously with systemd or PM2

Do not rely on an interactive node app.js shell session for a production service. Use a service/process manager so the application can be monitored and restarted according to a defined policy.

Option Best For Key Advantage
systemd Administrators wanting native Ubuntu service management Integrated service lifecycle, logging and boot management
PM2 Node.js teams wanting Node-focused process management Convenient app management, logs and startup integration

Option A: Run Node.js with systemd

First determine the exact Node.js binary path:

which node

It may look similar to:

/home/deploy/.nvm/versions/node/v26.x.x/bin/node

Use the actual path returned by your server when creating the service.

sudo nano /etc/systemd/system/nodeapp.service

Example unit:

[Unit]
Description=Net2Secure Node.js Application
After=network.target

[Service]
Type=simple
User=deploy
Group=deploy
WorkingDirectory=/home/deploy/apps/nodeapp
EnvironmentFile=-/home/deploy/apps/nodeapp/.env
ExecStart=/home/deploy/.nvm/versions/node/v26.x.x/bin/node /home/deploy/apps/nodeapp/app.js
Restart=on-failure
RestartSec=5
NoNewPrivileges=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target
Replace v26.x.x with the exact version directory returned by which node. If NVM later installs a different Node.js version, update the systemd service's ExecStart path before removing the old runtime.

Reload systemd and start the service:

sudo systemctl daemon-reload
sudo systemctl enable --now nodeapp
sudo systemctl status nodeapp --no-pager

View application logs:

sudo journalctl -u nodeapp -f

Option B: Run Node.js with PM2

If you prefer PM2, do not simultaneously run the same application on the same port with systemd.

npm install -g pm2

cd ~/apps/nodeapp

pm2 start app.js --name nodeapp

pm2 status
pm2 logs nodeapp

Save the current process list:

pm2 save

Generate the startup configuration:

pm2 startup

PM2 will print a command containing the appropriate user, home directory and Node.js path. Run the exact command PM2 generates, then run:

pm2 save

Configure Nginx as a Reverse Proxy

Rather than exposing the Node.js application directly to the Internet, Nginx can accept public HTTP/HTTPS traffic and proxy requests to the application listening on 127.0.0.1:3000.

Install Nginx

sudo apt update
sudo apt install nginx -y

sudo systemctl status nginx --no-pager

Create an Nginx Server Block

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

Replace example.com with your actual domain:

server {
    listen 80;
    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 Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
    }
}

Enable the configuration:

sudo ln -s /etc/nginx/sites-available/nodeapp /etc/nginx/sites-enabled/nodeapp

sudo nginx -t
sudo systemctl reload nginx

If this is the only site on the server and the default Nginx site is no longer required, you can disable the default server block:

sudo rm -f /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl reload nginx

Using WebSockets?

Applications using WebSocket connections require additional Nginx proxy configuration. Add the appropriate Upgrade and Connection handling only when your application requires WebSockets rather than copying it into every deployment unnecessarily.

Secure the Ubuntu VPS with UFW

Ubuntu documents UFW as its default firewall configuration tool. Before enabling it, make sure SSH access is explicitly allowed so you do not lock yourself out.

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'

sudo ufw enable
sudo ufw status verbose

Because Node.js is listening only on 127.0.0.1:3000, port 3000 does not need to be opened publicly for this deployment architecture.

Enable HTTPS with Certbot and Let's Encrypt

Before requesting a certificate, confirm that your domain's DNS records resolve to this VPS and that HTTP traffic can reach Nginx.

Certbot currently recommends Snap for most Linux installations. If you do not already have another Certbot installation:

sudo snap install --classic certbot

sudo ln -s /snap/bin/certbot /usr/local/bin/certbot

If the symbolic link already exists, do not create a duplicate.

Request and configure HTTPS through Nginx:

sudo certbot --nginx

Then test certificate renewal:

sudo certbot renew --dry-run

Certbot's supported installation methods configure automated renewal mechanisms, but a dry-run is useful for confirming that your server can renew certificates successfully.

Keep Ubuntu and Node.js Secure

Deploying the application is only the beginning. Production Node.js hosting also requires ongoing maintenance.

Keep Ubuntu Updated

sudo apt update
sudo apt upgrade

Check the automatic update service:

sudo systemctl status unattended-upgrades --no-pager

Ubuntu Server includes support for automatic security updates, but you should still maintain an operational update and reboot policy appropriate for your application.

Keep Node.js on a Supported Release

node -v
nvm ls
nvm ls-remote --lts

Test application compatibility before moving a production workload to a new Node.js major version.

Use Reproducible Dependency Installation

For an application repository containing a valid package-lock.json, a production deployment can use:

npm ci --omit=dev

Keep the lockfile under version control and review dependency changes during deployment.

Do Not Run the App as Root

The Node.js process normally does not need root privileges when Nginx is serving public ports 80 and 443. Run the application as its deployment or service user instead.

Do Not Expose the Node.js Port Unless Necessary

With the reverse-proxy architecture used in this guide, Nginx is public while Node.js listens only on localhost. This reduces unnecessary direct exposure of the application service.

Need an Ubuntu VPS for Your Node.js Application?

Compare Net2Secure Ubuntu and Linux VPS options for APIs, application servers, development environments and other Node.js workloads. Select resources according to your application's measured CPU, memory, storage and network requirements.

Production Deployment Workflow for an Existing Node.js Project

For an existing Git-based application, a typical deployment workflow may look like the following. Adapt the branch, build command and application lifecycle to your project.

cd ~/apps

git clone YOUR_REPOSITORY_URL nodeapp

cd nodeapp

npm ci --omit=dev

# If your project requires a production build:
# npm run build

# systemd deployment:
sudo systemctl restart nodeapp

# OR, if PM2 is your chosen process manager:
# pm2 restart nodeapp --update-env
Avoid running both systemd and PM2 as independent supervisors for the same application process. Select one process-management strategy and document it for your deployment team.

Node.js VPS Performance Optimization

There is no universal VPS size that guarantees a particular Node.js performance level. Measure the application under a representative workload before increasing server resources.

Area What to Monitor Possible Action
CPU Sustained CPU utilization and event-loop-heavy tasks Optimize code, offload jobs or scale processing capacity
Memory Node.js heap usage, system RAM and swap activity Investigate leaks or increase memory when justified
Storage Disk latency, database I/O and log growth Optimize storage access and log retention
Network Latency, throughput and connection volume Review server location, proxy settings and architecture
Application Response times, error rate and request throughput Profile bottlenecks before adding resources

Choose a VPS Location Appropriate for Your Users

Network distance and routing can affect latency. If your Node.js application primarily serves visitors in India, evaluate a Node.js hosting India deployment by measuring real network latency and application response times from your target audience. Geographic proximity alone does not guarantee application performance; network routing and application design also matter.

Use Nginx for the Public HTTP Layer

Nginx can handle the Internet-facing HTTP/HTTPS connection while Node.js serves application requests behind it. This also gives you a central place to manage TLS, proxy headers and HTTP-layer configuration.

Scale Only After Measuring

Before increasing VPS CPU or RAM, determine whether the bottleneck is CPU, application code, database queries, external APIs, memory pressure, storage I/O or network latency. Scaling infrastructure cannot compensate for every application bottleneck.

Troubleshooting Node.js on Ubuntu VPS

Problem Diagnostic Command What to Check
Application will not start sudo journalctl -u nodeapp -n 100 Node path, permissions, environment variables and stack trace
PM2 app is offline pm2 logs nodeapp Runtime errors, missing environment variables and dependencies
Nginx returns 502 curl http://127.0.0.1:3000 Confirm Node.js is listening on the expected local port
Nginx configuration fails sudo nginx -t Syntax errors and duplicate server blocks
Cannot reach website sudo ufw status Ports 80/443, DNS and upstream network firewall
Unsure which process owns port 3000 sudo ss -ltnp | grep :3000 Duplicate process or unexpected service
Nginx proxy error sudo tail -f /var/log/nginx/error.log Connection refused, timeout or permissions
Certificate renewal concern sudo certbot renew --dry-run DNS, ports, certificate configuration and renewal process

Node.js Ubuntu VPS Deployment Checklist

  • Use a currently supported Ubuntu release.
  • Install available operating-system security updates.
  • Create and use a non-root deployment account.
  • Configure SSH keys and confirm access before tightening SSH settings.
  • Use a supported Node.js LTS release.
  • Keep secrets outside source code.
  • Use a dependency lockfile.
  • Run the application with systemd or PM2.
  • Bind the application to localhost when using Nginx.
  • Configure Nginx as the public reverse proxy.
  • Enable UFW without blocking SSH access.
  • Allow only ports required by the workload.
  • Configure HTTPS for public production applications.
  • Test TLS certificate renewal.
  • Monitor Node.js and Nginx logs.
  • Monitor CPU, RAM, storage and application response times.
  • Maintain backups appropriate to the application and database.
  • Test updates before applying major runtime changes to production.

Test Your Node.js Workload Before Production

If you want to evaluate a VPS environment for a Node.js project, review Net2Secure's current trial pages and confirm the available operating system, resources, eligibility and activation conditions before testing.

Frequently Asked Questions About Node.js Hosting on Ubuntu VPS

Is Ubuntu VPS good for Node.js hosting?

Yes. A supported Ubuntu VPS can provide a configurable Linux environment for Node.js applications, including control over the runtime version, npm packages, Nginx, process management, firewall and TLS configuration. The correct VPS resources depend on the specific application and traffic profile.

How do I deploy Node.js on an Ubuntu VPS?

Install a supported Node.js LTS release, transfer your application, install dependencies, run the application under a non-root account, manage the process with systemd or PM2, configure Nginx as a reverse proxy, enable the firewall and add HTTPS for public production use.

Should I use PM2 or systemd for Node.js?

Both can manage a Node.js application. systemd is Ubuntu's native service manager and integrates directly with the operating system. PM2 provides Node.js-focused process-management features. Choose one primary process supervisor for each application rather than running competing supervisors for the same process.

Do I need Nginx for Node.js hosting?

Node.js can serve HTTP directly, but Nginx is commonly used as an Internet-facing reverse proxy for production deployments. It can proxy requests to Node.js on localhost and provide a central layer for TLS and HTTP configuration.

Which Node.js version should I install on Ubuntu VPS?

Use a currently supported Node.js LTS release that your application supports. At this article's November 2026 technical verification, Node.js 26.x is an LTS line. Re-check the official Node.js release schedule when deploying or upgrading because support status changes.

Which Ubuntu version should I use for Node.js hosting?

For production hosting, a supported Ubuntu LTS release is generally a practical choice because of its longer maintenance lifecycle. Ubuntu 26.04 LTS and Ubuntu 24.04 LTS are supported at the time this guide was reviewed. Verify the Ubuntu lifecycle before a new deployment.

Should Node.js run as root on a VPS?

Normally, no. Run the application under an unprivileged account and let Nginx handle public HTTP and HTTPS connections. Administrative privileges should be used only when required for server management.

Should I open port 3000 in the Ubuntu firewall?

Not for the reverse-proxy configuration in this guide. Node.js listens on 127.0.0.1:3000, while Nginx handles public traffic on ports 80 and 443. Open the Node.js application port publicly only when your architecture specifically requires it.

How do I add SSL to a Node.js application on Ubuntu VPS?

Point the domain to the VPS, configure Nginx for the domain and obtain a trusted TLS certificate. Certbot can integrate with Nginx to obtain and configure a Let's Encrypt certificate. Test renewal after setup.

Why does Nginx show a 502 Bad Gateway error with Node.js?

A 502 error frequently means Nginx cannot successfully communicate with its configured upstream application. Check that the Node.js process is running, confirm the host and port, inspect application logs and test curl http://127.0.0.1:3000 directly from the VPS.

How much RAM does a Node.js VPS need?

There is no reliable universal RAM requirement. Memory needs depend on the framework, application code, traffic, Node.js heap usage, databases, caches and additional services. Start from measured workload requirements and monitor memory usage before scaling.

Can I host multiple Node.js applications on one Ubuntu VPS?

Yes, provided the VPS has sufficient resources. Run each application on its own local port and create separate Nginx server blocks or routing rules. Keep service configurations, environment variables, permissions and logs clearly separated.

Can I use an Ubuntu VPS in India for Node.js hosting?

Yes. Businesses and developers serving Indian users can evaluate Ubuntu VPS infrastructure in India for Node.js applications. Measure network latency and application performance from your actual user locations rather than assuming geography alone guarantees faster performance.

Can I test a VPS before moving my Node.js application?

Net2Secure publishes VPS trial and Linux VPS trial information. Review the current trial pages and confirm eligibility, operating system availability, resources and testing conditions before deployment.

Final Takeaway

A secure Node.js VPS deployment is more than installing Node and running npm start. Use a supported Ubuntu and Node.js release, run application processes without root privileges, keep Node.js behind Nginx, expose only required network services, use HTTPS, maintain security updates and monitor application health.

For developers comparing hosting environments, Net2Secure provides information about Ubuntu VPS hosting , Linux VPS hosting and  VPS hosting . Choose infrastructure based on the measurable requirements of your application rather than relying on a generic VPS size recommendation.

Deploy Your Node.js Application on Ubuntu VPS

Compare a suitable VPS environment, deploy your Node.js stack and validate your application under realistic workload conditions before moving production traffic.

Editorial note: Technical instructions were verified against official documentation on November 17, 2026. Software versions, support lifecycles and installation methods should be revalidated when this guide is updated.


Abhay Pratap Singh

By Abhay Pratap Singh

Abhay Singh is a digital marketing strategist, technology writer, and SEO specialist with a passion for helping businesses grow through data-driven digital solutions. He specializes in search engine optimization (SEO), web hosting technologies, cybersecurity trends, cloud computing, website performance optimization, and emerging digital innovations.

With years of experience in content strategy and technical SEO, Abhay has authored numerous in-depth guides, tutorials, and industry insights that help businesses, website owners, and IT professionals navigate the evolving digital landscape. His expertise spans website optimization, DNS management, web hosting infrastructure, cybersecurity best practices, and AI-driven digital marketing strategies.

View all of Abhay Pratap Singh's posts.

Contact Us

Latest Articles

We use cookies

By continuing to browse this site, you are agreeing to the use of cookies to enhance your experience.

EXCLUSIVE CLOUD OFFER • GET ₹2,000 FREE CLOUD CREDITS!

Claim ₹2,000 Credits

Signup with Net2Secure and make your first recharge of ₹2,000 to get additional ₹2,000 add-on credits.

Only for New Customers • Terms Apply

Get ₹2,000
Free Cloud Credits!

Supercharge your workloads with Net2Secure enterprise cloud infrastructure. High speed, zero upfront commitment!

₹2,000 FREE CLOUD CREDITS
✦
✦
  • Get ₹2,000 Wallet Bonus on first recharge
  • High-Speed Cloud Server Deployment
  • 24/7 Dedicated Server Support & 99.95% Uptime