Appearance
PM2
The PM2 package is used to host multiple Nodejs apps running on the EC2 instance. Each app runs as a Nodejs process and connects to a single bot.
- Discord Nodejs app > Discord bot
- Telegram Nodejs app > Telegram bot
Scripts
There are several scripts in the package.json file that will execute PM2 commands for the bot. Both the Discord and Telegram apps have the same PM2 scripts. The only difference is the name applied to the Nodejs instance by PM2.
Below are the PM2 scripts, with the exception of start-dev, for Discord. Telegram will have the same scripts but with --telegram as the PM2 instance name.
"start-prod-pm2": "NODE_ENV=production pm2 start src/index.js --name discord",
"stop-prod-pm2": "NODE_ENV=production pm2 stop discord",
"restart-prod-pm2": "NODE_ENV=production pm2 restart discord",
"delete-prod-pm2": "NODE_ENV=production pm2 delete discord",
"start-dev": "NODE_ENV=development node src/index.js",
"start-dev-pm2": "NODE_ENV=development pm2 start src/index.js --name discord-dev",
"stop-dev-pm2": "NODE_ENV=development pm2 stop discord-dev",
"restart-dev-pm2": "NODE_ENV=development pm2 restart discord-dev",
"delete-dev-pm2": "NODE_ENV=development pm2 delete discord-dev"pnpm start-prod-pm2
Starts a bot instance if one is not already running. The bot will be visible in the PM2 list of running processes which is presented after the above script runs. The column label ↺ shows the number of start/restarts for the instance.
sh
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ discord │ fork │ 0 │ online │ 0% │ 18.3mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘pnpm restart-prod-pm2
Restarts the bot instance only if it is already running. The bot will be visible in the PM2 list of running processes which is presented after the script runs.
The column label ↺ show the number of start/restarts for the instance.
sh
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ discord │ fork │ 1 │ online │ 0% │ 10.3mb │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘pnpm stop-prod-pm2
Stops the bot instance only if it is already already running. The bot will be visible in the PM2 list of running processes which is presented after the script runs but now with a status of stopped.
The column label ↺ show the number of start/restarts for the instance.
sh
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ discord │ fork │ 1 │ stopped │ 0% │ 0b │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘pnpm delete-prod-pm2
Removes (deletes) the bot instance only if it is already already running. The bot will not longer be visible in the PM2 list of running processes which is presented after the script runs.
sh
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘Useful PM2 commands
The most commonly used monitoring PM2 commands are pm2 list and pm2 monit.

