使用PM2运行自定义的npm脚本 [英] Run a custom npm script with PM2

查看:466
本文介绍了使用PM2运行自定义的npm脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在开发多个Telegram机器人,但我想将所有机器人都保留在同一个git存储库中.问题是,另一方面,我想将它们作为单独的进程运行.

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.

因为我使用的是Telegraf框架,所以要运行一个机器人,它会变成:micro-bot src/bot-one/bot.js

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

使用PM2进行操作时会出现问题.我已经能够使用npm start脚本运行这样的机器人之一:

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"
}

但是,PM2命令将如何运行两个自定义脚本中的每一个?我在考虑将bot令牌设置为系统的环境变量,以简化操作.

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.

推荐答案

尝试一下:

pm2 start npm -- run littleAppleBot --

pm2 start npm -- run weatherWarnBot --

这篇关于使用PM2运行自定义的npm脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆