Node.js is a powerful runtime for running JavaScript outside the browser, perfect for scalable web apps. PM2, a process manager for Node.js, ensures uptime and simplifies management. This guide walks you through installing Node.js and PM2 on an AvaHost Ubuntu VPS (20.04/22.04/24.04), with practical examples to deploy and manage applications efficiently.
AvaHost VPS with Ubuntu 20.04, 22.04, or 24.04.
Root access or sudo privileges (see prior SSH guide).
Basic Linux command knowledge.
A static IP or domain (e.g., app.yourdomain.com).
Before installing Node.js and PM2, update your package list to ensure you have the latest versions available:
sudo apt update && sudo apt upgrade -yThere are multiple ways to install Node.js on Ubuntu 20.04. We will use the NodeSource repository to get the latest stable version.
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -Replace 18.x with the latest LTS version if necessary.
sudo apt install -y nodejsnode -v
npm -vThis should output the installed versions of Node.js and npm.
PM2 is a process manager that helps keep your Node.js applications running.
sudo npm install -g pm2pm2 -vThis should return the installed version of PM2.
To demonstrate PM2, we will create a simple Node.js application and run it.
mkdir myapp && cd myapp
echo "console.log('Hello from Node.js!');" > app.jspm2 start app.jspm2 listpm2 savepm2 startupFollow the instructions provided by the command to complete the setup.
PM2 provides various commands to manage and monitor applications:
pm2 restart app.jspm2 stop app.jspm2 delete app.jspm2 logsInstalling Node.js and PM2 on an AvaHost Ubuntu VPS is simple and enables robust app management. The examples, like running app.js with PM2 or setting up Nginx, ensure your apps are scalable and reliable. With AvaHost’s high-performance infrastructure, you can deploy Node.js applications with confidence, ensuring uptime and easy monitoring. Explore PM2’s features (man pm2) and AvaHost’s VPS plans to power your projects.