How to Install Node.js on a VPS Server

Here’s a step-by-step guide to installing Node.js on a VPS server (suitable for Ubuntu-based systems):


How to Install Node.js on a VPS Server

Step 1: Connect to Your VPS

Use SSH to log in to your server:

ssh your-username@your-server-ip

Replace your-username and your-server-ip with your actual SSH credentials.


Step 2: Update Your System

Before installing anything, update the package index:

sudo apt update && sudo apt upgrade -y

Step 3: Install Node.js (Recommended Method via NodeSource)

  1. Add the NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

You can replace 18.x with the version you want (e.g., 20.x for the latest LTS).

  1. Install Node.js:

sudo apt install -y nodejs
  1. Verify Installation:

node -v
npm -v

Step 4: (Optional) Install Build Tools

Some Node packages need build tools. Install them with:

sudo apt install -y build-essential

Step 5: Run a Simple Node App (Test)

  1. Create a file:

nano app.js
  1. Paste this code:

const http = require('http');
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.end('Hello from your VPS!');
});

server.listen(port, () => {
  console.log(`Server running at http://localhost:${port}/`);
});
  1. Start the app:

node app.js
  1. Visit http://your-server-ip:3000 in your browser.


Bonus: Keep App Running in Background

Use PM2, a process manager:

sudo npm install -g pm2
pm2 start app.js
pm2 startup
pm2 save

Need Help?

If you're using a managed VPS (e.g., from Sun Servers), reach out to your hosting provider for assistance setting up or maintaining your Node.js environment.


Let me know if you want the guide tailored for CentOS, Debian, or with Docker instead.

  • How to Install Node.js on a VPS Server
  • 0 Користувачі, які знайшли це корисним
Ця відповідь Вам допомогла?

Схожі статті

VPS Security Tips to Prevent Attacks on Your Server

SEO Title: VPS Security Tips to Prevent Attacks on Your ServerMeta Description: Protect your...

Powered by WHMCompleteSolution