node.js - 使用forever运行多个脚本

标签 node.js ubuntu forever

我在一个目录中有几个脚本,每个脚本都称为 bot 及其编号,从 1 到脚本的数量。

我想做的是通过终端(使用 Ubuntu)通过 1 个命令行运行所有脚本,我使用 forever 命令来运行脚本而不停止等等。

你能通过终端或者使用 Node js 脚本来实现吗?

是否还有其他命令(例如“forever”)可以为我完成此操作?

最佳答案

您可以通过命令行使用命令forever来使用它。

您需要使用所需的文件创建一个 JSON 文件。

示例:

[
  {
    // App1
    "uid": "app1", // ID of the script.
    "append": true,
    "watch": true,
    "script": "bot1.js", // Name of the script
    "sourceDir": "" // Where the script is located. If it's in the
                    // same location as the json file, leave it ""
  },
  {
    // App2 = > Same as app1, just different script name.
    "uid": "app2",
    "append": true,
    "watch": true,
    "script": "bot2.js",
    "sourceDir": ""
  }
]

然后您只需通过 forever 命令运行 JSON 文件即可。 示例:

forever start apps.json

您可以查看有关永远的更多信息here .

关于node.js - 使用forever运行多个脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50756647/

相关文章:

angularjs - Angular Node 路由

node.js - 无法在控制台中看到 MediaStream 属性值

javascript - node.js 对象在数据库中的自动持久化

linux - 是否可以将两个 tr 命令合二为一?

node.js - 为什么我的 Node.js 服务器进程被克隆?

node.js - Sequelize NodeJS 服务器抛出 "ERR_UNKNOWN_ENCODING"错误

c++ - Qt5.1加载平台插件xcb失败

c++ - 一个 exec 函数中的多个终端命令

ember.js - 永远使用 Ember-CLI

Node.js 永远带有环境变量