Linux

Keeping your Discord bot online 24/7 with Node.js and PM2

Install Node.js, upload your bot and let PM2 keep it alive: it starts with the VPS, restarts if it crashes and keeps the logs. Python bots too.

1 min readUpdated on 6 October 2026

A Discord bot uses very little: the smallest plan with Linux is plenty. What it does need is to be on all the time, and that is what PM2 is for.

1. Install Node.js

The current LTS from the official NodeSource repository:

curl -fsSL https://deb.nodesource.com/setup_22.x | bash -
apt install -y nodejs
node -v

2. Upload your bot

With git clone if it is on GitHub, or by uploading the folder over SFTP (how). Then, in its folder:

cd /root/mybot
npm install

Put the bot token in its .env file (or wherever your code reads it). Never push it to GitHub or paste it into a ticket.

3. Start it with PM2

npm install -g pm2
pm2 start index.js --name mybot

Replace index.js with your bot's entry file (the one in the "main" field of its package.json).

4. Start it with the VPS

pm2 save
pm2 startup systemd

pm2 save stores the process list and pm2 startup restores it on every boot.

Day to day

pm2 status              # is it online?
pm2 logs mybot          # see what it writes (Ctrl + C to exit)
pm2 restart mybot       # restart it after changing the code
pm2 monit               # live CPU and memory usage

Is your bot written in Python?

PM2 handles it too:

apt install -y python3-venv
cd /root/mybot
python3 -m venv venv
venv/bin/pip install -r requirements.txt
pm2 start bot.py --name mybot --interpreter venv/bin/python3

Then the same pm2 save from step 4.

Related articles

Back to the help centre

Can’t find what you need?

Open a ticket from your panel and we will answer in under 5 minutes.