test

Constatic

Discord Bot BaseHosting

PM2

How to host discord bot project using pm2

PM2 is a daemon process manager that will help you manage and keep your application online.

To get started, install pm2 globally:

npm install -g pm2

Create a file in the project root to run the start script. Name it pm2.start.mjs:

pm2.start.mjs
import { exec } from "node:child_process";
exec("npm run start", { windowsHide: true });

Then you can start your application using this command:

pm2 start --name my-bot ./pm2.start.mjs

You can set a custom name for your process using the --name flag

Done, your application will run in the background on the machine.

Below are some useful commands you can use to manage your process:

ComandoUsoDescrição
listpm2 listDisplays all registered processes
stoppm2 stop my-botStop your application process
restartpm2 restart my-botRestart your application process
logspm2 logs my-botDisplays your application's process logs
deletepm2 delete my-botDelete your application process

On this page

No Headings