14

I am currently developing several Telegram bots but I want to keep all of them in the same git repository. The issue is that on the other hand, I want to run them as separate processes.

Since I'm using the Telegraf framework, to run a bot it goes such as: micro-bot src/bot-one/bot.js

The problem comes when doing this with PM2. I've been able to run one of the bots with the npm start script like this:

pm2 start --name "WeatherBot" npm -- start -- -t <
TOKEN>

But I'd like to be able to create custom scripts like this:

"main": "src/weatherWarnBot/bot.js",
"scripts": {
    "start": "micro-bot",
    "littleAppleBot": "micro-bot src/littleAppleBot/bot.js",
    "weatherWarnBot": "micro-bot src/weatherWarnBot/bot.js"
}

But, how would the PM2 command be to run each of the two custom scripts? I was thinking of having the bot tokens set as enviroment variables of the system, for simplification.

Javier García Manzano
  • 1,024
  • 2
  • 12
  • 25

4 Answers4

23

Try this:

pm2 start npm -- run littleAppleBot --

pm2 start npm -- run weatherWarnBot --

zhangjinzhou
  • 2,461
  • 5
  • 21
  • 46
5

Use this :-

pm2 start --name "Script Name" npm -- run <YOUR CUSTOM SCRIPT> --

Gaurav
  • 1,668
  • 1
  • 13
  • 30
2
pm2 start npm --name "Your APP Name" -- start
0

how bout this:

pm2 start "micro-bot src/bot-one/bot.js"
user3413723
  • 11,147
  • 6
  • 55
  • 64