Run a custom npm script with PM2

Viewed 12310

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.

3 Answers

Try this:

pm2 start npm -- run littleAppleBot --

pm2 start npm -- run weatherWarnBot --

Use this :-

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

pm2 start npm --name "Your APP Name" -- start
Related