Key takeaways
- A VPS gives you control over Node.js versions, packages, ports, and server settings.
- NVM, PM2, and Nginx provide a strong foundation for production applications.
- HTTPS, firewall rules, monitoring, and backups help protect the application after launch.
- Check application and database performance before upgrading the VPS.
Running Node.js on a VPS gives you direct control over the runtime, networking, and deployment process. This makes VPS hosting a good fit for APIs, dashboards, ecommerce backends, and real-time applications that need persistent connections or custom server settings.
What is Node.js on a VPS?
Node.js is an open-source JavaScript runtime that lets developers execute JavaScript outside a web browser. A VPS provides an isolated virtual server with allocated CPU, RAM, storage, and administrative access.
Running Node.js on a VPS means hosting the application and runtime in a virtual server that you control. Shared hosting often restricts runtime versions, background processes, and custom configuration. Serverless platforms reduce server administration but may introduce execution limits, cold starts, or less control over the environment.
A VPS offers more flexibility, but it also gives you more responsibility for deployment, updates, security, and monitoring.
Why run Node.js on a VPS?
Control over the server environment
You can select the operating system and Node.js version, install system and npm packages, configure network access, and manage application processes.
This control helps when an application relies on native packages, background jobs, environment variables, or integrations that a shared platform may not support.
Support for real-time applications
Node.js uses an event-driven, non-blocking architecture that works well for applications handling many concurrent connections. Common examples include chat tools, games, notifications, collaborative applications, and live dashboards.
A VPS also supports persistent WebSocket connections without the execution limits that some serverless environments impose.
Predictable resources and costs
A VPS gives the application allocated CPU, RAM, and storage. This can make capacity planning and monthly costs more predictable for applications with steady traffic.
A VPS won’t always cost less than serverless hosting. The better choice depends on traffic patterns, resource requirements, support needs, and how much time your team can spend managing the environment.
Managed support with administrative control
Managed VPS hosting can reduce the time your team spends on operating system maintenance, patching, monitoring, and server-level troubleshooting. You can still retain the access needed to configure and deploy your application.
Managed support doesn’t replace code testing, dependency management, application debugging, or database optimization. Review the provider’s management scope before deploying a production workload.
Before you deploy Node.js on a VPS
Before starting, confirm that you have an Ubuntu VPS with root or sudo access, a domain pointed to the server, deployable application code, the correct internal port and environment variables, a database plan, and a way to back up or restore the application.
Choose a supported Node.js version
Node.js publishes Current and Long-Term Support releases. Production applications should generally use an active or maintenance LTS version unless the project requires another supported release.
Avoid choosing a version based only on an older tutorial. Confirm that the application framework, packages, and build tools support the version you plan to install.
Estimate your resource needs
A small API or development application may run on one or two virtual CPUs and 1 to 2 GB of RAM. A business application with more concurrent users, database activity, or background jobs may need more CPU and memory.
Real-time applications, high-traffic APIs, and clustered processes may require 4 GB of RAM or more. Treat these figures as starting points. Application design, traffic, caching, logging, and database placement can significantly change resource use.
How to install and deploy Node.js on a VPS
The following steps create a direct Ubuntu deployment. Commands and paths may vary based on your operating system, username, domain, and application structure.
1. Connect to the VPS with SSH
Open a terminal and connect to the server:

Use a non-root account with sudo privileges for routine administration. Running every command as root increases the effect of configuration mistakes or compromised processes.
2. Update the server
Update the package index and installed packages:

This gives you current operating system packages and security fixes. Reboot the VPS if the updates install a new kernel or require a restart:

Reconnect through SSH after the server comes back online.
3. Install Node.js with NVM
Node Version Manager, or NVM, lets you install and switch between Node.js versions from the command line. This makes it useful for testing upgrades and maintaining applications with different runtime requirements.
Install NVM using the current command from the official NVM repository. Because the release number changes, verify the installer URL in the NVM documentation before running it.
After installation, reload the shell configuration:

Install the latest supported LTS release:

Set it as the default version for new shell sessions:

4. Verify Node.js and npm
Confirm that Node.js and npm installed correctly:

Both commands should return version numbers. Resolve any installation errors before deploying the application.
5. Create an application directory
Create a dedicated directory for the application:

A dedicated directory keeps the deployment separate from personal files and makes permissions and backups easier to manage.
6. Deploy the application code
Clone the project into the application directory:

When the project includes a current package-lock.json file, install production dependencies with:

npm ci installs the versions recorded in the lockfile and creates a more repeatable build. Use npm install when the project doesn’t include a compatible lockfile.
7. Configure environment variables
Don’t hard-code API keys, database passwords, or other credentials in the application repository.
A simple .env file might contain:

Restrict access to the file:

Larger applications may benefit from a dedicated secrets-management system instead of a local file.
8. Test the application locally
Start the application temporarily:

Replace server.js with the project’s actual entry file.
From another terminal session, test the application on its internal port:

Confirm that the application responds, then stop the temporary process with Ctrl+C.
Keep the Node.js application running with PM2
Starting an application with node server.js ties the process to the terminal session. Closing the session stops the application.
PM2 manages Node.js processes and can restart applications after crashes or server reboots.
Install PM2
Install PM2 globally:

Start the application
Start the application and assign a recognizable process name:

For an application that uses an npm start script, run:

Check the process:

Restore the process after a reboot
Generate the startup configuration:

PM2 will display another command. Run that command with the permissions shown in the output.
Save the current process list:

Review application logs
View real-time logs:

Review process status, CPU use, and memory use with:

PM2 can restart a failed process, but it cannot correct application bugs, failed database connections, or inefficient code.
Configure Nginx as a reverse proxy
A production Node.js application usually listens on a private local port while Nginx handles public traffic.
Nginx can route requests to Node.js, terminate HTTPS connections, serve static files, and forward WebSocket traffic.
Install Nginx

Confirm that the service runs:

Create a server block
Create a domain-specific configuration:

Add the following configuration, then update the domain and application port:

The Upgrade and Connection headers let Nginx forward WebSocket connection upgrades.
Enable the server block:

Test the configuration:

If the test succeeds, reload Nginx:

Disable the default Nginx configuration if it conflicts with the application’s domain.
Configure the firewall and HTTPS
Restrict firewall access
Allow SSH before enabling the firewall so you don’t lock yourself out:

Review the active rules:

Most public Node.js applications only need SSH, HTTP, and HTTPS open. Keep the internal application port private unless the use case requires direct access.
Add HTTPS with Certbot
Your domain must resolve to the VPS before Certbot can validate and install a certificate through Nginx.
Install Certbot:

Request and configure the certificate:

Test certificate renewal:

Secure Node.js on a VPS
A production deployment needs protection at the server, runtime, dependency, and application levels.
Limit administrative access
Use SSH keys instead of passwords where possible. Restrict root login, remove inactive accounts, and grant each administrator only the permissions required for their work.
Use multifactor authentication for hosting portals, source-control accounts, and monitoring platforms that support it.
Protect application secrets
Don’t commit .env files, API keys, database passwords, or certificate credentials to source control.
Rotate exposed secrets immediately. Review file permissions and confirm that only the application account can access sensitive configuration.
Keep software current
Keeping your Node.js installation up to date is important for maintaining performance and security.
Update the operating system, Node.js LTS release, npm dependencies, PM2, Nginx, and other software in the application stack. Test updates in staging before applying them to production.
Run the following command to review known npm dependency issues:

Don’t apply every automated fix without review. Major dependency changes can break the application.
Limit public ports
Expose only the network services the application needs. Use Nginx for public web traffic and limit access to databases, caches, and internal ports.
Monitor and optimize Node.js performance
A slow or unstable application doesn’t always need a larger VPS. Review the application, database, configuration, and resource use before increasing server capacity.
Review logs and resources
Start with:

These commands help you review process state, recent errors, memory, and storage.
External uptime monitoring and application performance tools can provide additional visibility into response times, failures, event-loop delay, and database activity.
Check database performance
Slow database queries can make an application appear underpowered even when the VPS has unused resources.
Review query execution time, indexes, connection limits, and connection pooling. Avoid opening a new database connection for every request.
Add caching where it helps
Caching can reduce repeated database queries and improve response times. You may use in-memory caching for one process or Redis when several Node.js processes need access to the same data.
Use a shared store for sessions, rate limits, or other state when multiple processes must remain consistent.
Use multiple CPU cores
A single Node.js process primarily executes JavaScript on one main thread. PM2 cluster mode can start several application processes to use multiple CPU cores:

Before enabling cluster mode, confirm that the application doesn’t rely on local in-memory sessions or state. Use Redis or another shared store when processes need access to common data.
Decide where the database runs
You can run the database on the same VPS as the Node.js application or place it on a separate server or managed database service.
Keeping both on one VPS can reduce cost and network latency for smaller applications. However, the services compete for the same CPU, RAM, and storage and share the same failure point.
Separating the database can improve isolation, scaling, maintenance, and recovery. It also lets you increase application and database resources independently, but it costs more and requires secure network configuration.
Choose based on traffic, data importance, recovery requirements, and expected growth.
Plan backups, rollback, and recovery
Application code in Git doesn’t replace a complete backup. Back up the database, uploaded files, environment configuration, Nginx settings, PM2 configuration, and any other data required to restore the service. Store backups away from the production VPS.
Create a rollback process
Keep the previous application release, dependency lockfile, and environment configuration available until you confirm that a deployment works.
Review database migrations before deployment. Some schema changes need their own rollback plan because restoring an earlier application version may not reverse the database change. Test updates in staging and document the commands required to restore the prior release.
Test recovery
A completed backup job doesn’t prove that the backup will restore successfully. Run periodic restoration tests and document who handles application, database, and server recovery.
Managed vs. self-managed Node.js VPS hosting
A self-managed VPS gives your team control over the server environment, but you also handle operating system updates, security, monitoring, backups, and troubleshooting.
A managed VPS shifts defined server-level tasks to the hosting provider. Your team still manages the application code, dependencies, deployment process, and application performance.
| Task | Managed VPS | Self-managed VPS |
| Physical server and network | Provider | Provider |
| Operating system support | Provider within service scope | Customer |
| Server patching and monitoring | Often included within scope | Customer |
| Node.js application code | Customer | Customer |
| npm dependencies | Customer | Customer |
| Application configuration | Customer or shared, depending on scope | Customer |
| Database and code optimization | Customer | Customer |
| Backups | Depends on the plan | Customer configures |
If server maintenance is taking time away from development, managed VPS hosting can reduce server-level work while preserving application control.
Review the provider’s management scope carefully. Don’t assume that managed hosting includes application debugging, dependency upgrades, database tuning, or code changes.
Common Node.js on VPS problems
The application stops after you close SSH
The application probably runs directly through the node command.
Start it with PM2, configure the startup service, and save the process list:

Nginx returns a 502 Bad Gateway error
A 502 error often means Nginx cannot reach the Node.js process.
Check the application and Nginx configuration:

Confirm that the application runs on the port listed in proxy_pass.
npm installation fails
Check the Node.js version, lockfile, disk space, file ownership, native build tools, and npm error output.
Avoid running npm with sudo inside an NVM-managed application directory. Doing so can create file ownership problems.
The application cannot reach the database
Review the connection string, credentials, firewall rules, bind address, SSL requirements, and user permissions.
When the database runs on another server, confirm that both systems allow traffic through the required private or trusted network path.
The domain shows the default Nginx page
Check the DNS records, server_name, enabled site configuration, and default Nginx server block.
Test the configuration and reload Nginx after making changes:

WebSockets fail to connect
Confirm that the application supports WebSockets and that the Nginx configuration includes the required upgrade headers.
Also check the client URL, HTTPS settings, proxy timeouts, and application port.
The application runs slowly
Check logs, resource use, database performance, and event-loop activity before upgrading the VPS. A larger plan will not fix inefficient queries, blocked code, memory leaks, or repeated application errors.
Node.js on VPS FAQs
Node.js on VPS next steps
Deploying Node.js on a VPS involves more than installing the runtime. A production environment also needs process management, a reverse proxy, HTTPS, firewall controls, monitoring, backups, and a recovery plan.
Start by provisioning an Ubuntu VPS and confirming the application’s domain, port, Node.js version, database, and resource requirements. Complete the deployment in a staging environment before directing production traffic to it.
Liquid Web managed VPS hosting gives developers root access, allocated resources, and help with the underlying server environment. Explore Liquid Web VPS hosting to compare configurations and choose one that supports your application as it grows.
Related Resources
How to install Node.js on Linux (AlmaLinux)
Installing Node.js on Windows Servers
How to Configure and Deploy CloudLinux’s Node.js Selector


Josh Escobedo