How to Host Node.js app on VM with CloudPanel

Hey, I’m Ajink. In this blog post, I’ll guide you on Host Node.js app on your virtual machine server using Cloudpanel. Let’s get started!

How to Install Cloudpanel on Your VM:

Follow this link for a step-by-step guide: Cloudpanel Getting Started.

Alternatively, you can watch my video tutorial:

Get Started to Host Node Js app :

Follow this Blog or Watch Video :

step 01 : login to your cloudpanel :

click on New site :

select Create Node.js site

Ensure that your domain is pointing to the server’s IP address. You can achieve this by adding an A record that points to your server’s IP address. If another application is already running on port 3000, you have the option to change it to any other available port.

Step 02: Location of Your Application Files

If your application is hosted on GitHub , you can retrieve it using Git. Alternatively, if the files are on your local machine, you can upload them to the site’s file manager folder.

Like here inside the htdocs inside the website folder .

we have completed step 2 , if your app is on github we will see it in step 3

Step 03 : open command prompt , bash or linux terminal

login to ssh using

ssh <username>@<server IP address>

enter your password and login (you can refer first video for it)

as you are logged in now write below command

sudo su - <username created when website is added>
cd htdocs
cd <website address inside htdocs the folder we have>

if you are getting your app from github , if you uploaded dont do this step

git clone <github repo link>
ls
cd <folder you get with above ls command >

step 4 : run the app

npm install
npm run dev 

by any chance npm install is not working then add -force to it like

npm install -force
npm run dev

The node.js app will not start by itself in case the server reboots, so if you don’t want to go and manually start it we need to enable pm2 to auto-restart it.

npm install pm2@latest -g

after installing pm2

pm2 start npm --name <app name> -- <run command without np>
pm2 save

Add Cron To Start App On Reboot

echo $PATH

edit the crontab

crontab -e
PATH=<output of path>
@reboot pm2 resurrect &> /dev/null

completed done

references : https://www.bitdoze.com/install-cloudpanel-host-nodejs/

Team
Team

This account on Doubtly.in is managed by the core team of Doubtly.

Articles: 475