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.
To run the npm start script with Pm2, you can use the following command (make sure you call the command from inside your project folder): $ pm2 start npm -- start.
pm2 start npm -- run dev. pm2 start starts the process. npm here means you want to start the npm command. -- run dev means run dev is piped to npm. So basically you are running, pm2 start (npm run dev) If you want to add process name add it BEFORE npm: pm2 start --name="MyPRocess" npm -- run dev. Share.
First you need to go to that frontend folder where (or wherever) package.json is located then, pm2 start starts the process. npm here means you want to start the npm command. -- run dev means run dev is piped to npm. So basically you are running, pm2 start (npm run dev)
PM2 is an advanced process manager for running Node.js applications. That provides an easier option to automate a Node.js application. We can quickly do the start, stop, or other operations on applications. Many of the Node.js applications use “npm start” to run.
Use this :-
pm2 start --name "Script Name" npm -- run <YOUR CUSTOM SCRIPT> --
Try this:
pm2 start npm -- run littleAppleBot --
pm2 start npm -- run weatherWarnBot --
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With