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.jsandpackage.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.
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
Frequently asked questions
Related guides
Install Docker and Docker Compose on a Linux VPS
Complete guide to installing Docker and Docker Compose on a Linux VPS at Lordhosting: official repository, running without sudo.
Install Node.js with nvm on a Linux VPS
Install Node.js on a Linux VPS with nvm: version management, the NodeSource alternative, npm basics and keeping an app running 24/7 with PM2.
Install PufferPanel on a KVM VPS
Install the latest stable PufferPanel on a Lordhosting KVM VPS automatically, then manage your game servers from the admin panel.
How to Monitor Network Traffic on a VPS: Complete Guide & Tools
Learn how to monitor network traffic on your VPS with tcpdump, netstat, Wireshark. Control your servers, detect alerts and secure your network.

