KVM VPSKVM VPS

Install a Discord Bot on a KVM VPS

Complete guide to install and host a 24/7 Discord bot on a Lordhosting KVM VPS: Node.js installation, pm2, automatic startup and log management.

Hosting a Discord bot on your own PC has one obvious problem: as soon as the machine shuts down, the bot goes offline. A KVM VPS runs 24/7 and gives you a dedicated Linux environment, perfect for a Node.js bot. In this guide, you will install Node.js, transfer your bot files, and keep the bot online permanently with pm2, even after a crash or a server reboot.

Prerequisites

  • A KVM VPS running Debian or Ubuntu, reachable over SSH (the IP address and credentials are available in your Lordhosting client area)
  • An SSH client (terminal on Linux/macOS, PowerShell or PuTTY on Windows) and an SFTP client such as FileZilla or WinSCP
  • Your bot files (for example myfile.js and package.json) as well as its token, retrieved from the Discord Developer Portal

đź’ˇ If you haven't secured your VPS yet, follow our Secure a Linux VPS guide first.

1. Update your system

Connect to your server over SSH:

ssh root@your_ip

Then update the package list and the system:

sudo apt update && sudo apt upgrade -y

2. Install Node.js

Install Node.js from the NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -
sudo apt-get install -y nodejs

Adjust 16.x to the version required by your library: recent versions of discord.js require a newer Node.js LTS release. If in doubt, check your bot's package.json or the library documentation.

Want to put this guide into practice on your own server? Ryzen VPS hosting from €8/month at LordHosting, online in a few minutes.

3. Verify that it is properly installed

node -v
npm -v

Both commands should print a version number. If they don't, go back to step 2.

4. Import your bot files to your VPS

Two options:

  • SFTP: connect FileZilla or WinSCP with the same credentials as SSH (port 22) and upload the bot folder, for example to /root/my-bot.
  • Git: if your code is versioned, clone it directly on the server with git clone.

Do not upload the node_modules folder: it will be regenerated on the server in the next step. Also make sure your token is not hard-coded in your source files, but stored in a .env or config.json file.

5. Start your Discord bot

Move into the bot folder, install the dependencies, then start it:

cd /root/my-bot
npm install
node myfile.js

Your bot should now appear online on your Discord server. This first launch is a test: if you close the terminal, the bot stops. The next step fixes that.

6. Keep the bot online 24/7 with pm2

pm2 is a process manager for Node.js: it detaches the bot from your SSH session, restarts it automatically if it crashes, and starts it when the VPS boots.

sudo npm install -g pm2
pm2 start myfile.js --name my-bot
pm2 startup
pm2 save

The pm2 startup command prints a line to copy and paste to enable automatic startup, then pm2 save records the list of processes to bring back up.

7. Manage the bot and read the logs

A few useful day-to-day commands:

pm2 status          # bot status
pm2 logs my-bot     # live logs
pm2 restart my-bot  # restart after an update
pm2 stop my-bot     # stop the bot

Common Issues

"Error: Cannot find module 'discord.js'": the dependencies are not installed. Run npm install in the folder that contains the package.json file, not elsewhere.

"An invalid token was provided": the token in your .env or config.json is wrong or has been regenerated. Create a new one in the Discord Developer Portal (Bot tab → Reset Token) and update the file. Also remember to enable the Privileged Gateway Intents if your bot needs them.

The bot stops when you close the terminal: it was started directly with node. Relaunch it with pm2 (step 6) to detach it from your SSH session.


Your Discord bot now runs 24/7 on your KVM VPS, restarts on its own after a crash and survives server reboots. To go further, check our guide on monitoring network traffic on your VPS.

âť—Always Good to Know

  • If an error appears or your plugin doesn't work, don't hesitate to contact our support via ticket or via Discord
LordHosting

Put this guide into practice on your own server

From €8/month. Online in a few minutes, anti-DDoS protection, 7/7 support, no commitment.

Ryzen VPS hosting from €8/month

Frequently asked questions

Back to KVM VPS
Was this article helpful?
Welcome Offer

Sign up now and enjoy 10% off on your first order by entering the promo code: WELCOME

Logo LordHostingLordhosting is a SASU with a share capital of €1,000. SIREN 105 383 988 RCS Paris.
Copyright © 2026 LordHosting.