Back to Blog

How to Deploy Node Js App on VPS Server

Step 1. Purchase VPS Hosting

Begin by purchasing a Virtual Private Server (VPS) hosting plan from a reliable provider. Make sure to choose a plan that meets your project's requirements in terms of CPU, RAM, and storage. This will be the server where you will deploy your application.

Step 2. Copy the VPS IP Address

Once your VPS is set up, you will receive an IP address. This IP address is crucial as it allows you to access your server remotely. Make sure to copy and save this IP address for future use.

Step 3. Connect to Your VPS via SSH

Open your terminal on your local machine. To establish a secure connection to your VPS, type the following command, replacing the IP with your VPS's IP address:

bash
ssh root@159.100.9.20

This command will log you into your VPS as the root user. You may be prompted to enter a password or a passphrase if you have set up SSH keys.

Step 4. Update and Upgrade Your VPS

To ensure your VPS has the latest security patches and software updates, run the following commands:

bash
sudo apt update sudo apt upgrade

These commands will update the package lists and upgrade all installed packages to their latest versions.

Step 5. Install Node.js on Your VPS

Node.js is essential for running JavaScript applications on the server. Install it by executing:

bash
sudo apt install nodejs

This command will download and install Node.js on your VPS, allowing you to run JavaScript applications.

Step 6. Install Git

Git is a version control system that you will use to clone your project repository. Install it with:

bash
sudo apt install git

This command will install Git, enabling you to manage your project's source code.

Step 7. Clone Your GitHub Project

Navigate to your GitHub repository and copy the repository URL. Use the following command to clone your project onto the VPS:

bash
git clone <Repo URL>

Replace <Repo URL> with the actual URL of your GitHub repository. This will create a local copy of your project on the server.

Step 8. Navigate to Your Project Directory

Once your project is cloned, change into the project directory using the cd command:

bash
cd <Folder Name>

Replace <Folder Name> with the name of the directory created by the git clone command.

Step 9. Install the PM2 Package with npm

PM2 is a process manager for Node.js applications. It helps keep your application running smoothly. Install it using npm:

bash
npm install pm2 -g

The -g flag installs PM2 globally, making it accessible from anywhere on your server.

Step 10. Run Your Main File with PM2

Finally, start your application using PM2 to ensure it runs continuously, even if the server restarts:

bash
pm2 start <main-file>

Replace <main-file> with the name of your application's main file. PM2 will handle the process management, keeping your app running efficiently. Your application should now be up and running on your VPS.

Based in Greater Noida, IndiaCurrently