【问题标题】:How to use pm2 to run grunt serve如何使用 pm2 运行 grunt serve
【发布时间】:2017-04-25 09:37:44
【问题描述】:

我的同事给了我一个项目,你运行 grunt serve 来启动它。现在我正在尝试使用 pm2 在后台永远启动项目,这样我就可以关闭我的命令行。但是,我找不到正确的方法。

我见过类似的答案

cd /path/to/fullstack

pm2 start grunt --name website --serve

但我不太了解,而且我对咕噜声知之甚少。我只知道 grunt serve 为我同时运行多个任务。

我知道,如果我知道为我的应用程序创建 Web 服务器的基本 js 文件,例如 index.js。我可以运行 pm2 start index.js。

我尝试使用 node index.js 运行基本文件,但它给了我一个错误,因为我需要同时运行 babel,这是由 grunt serve 完成的。

谁能帮我使用 pm2 运行 grunt serve 命令?

【问题讨论】:

    标签: node.js deployment gruntjs pm2


    【解决方案1】:

    对于想知道如何在 2019 年实现这一目标的人来说,这里是解决方案。利用 PM2 和 PM2's Ecosystem File

    首先,创建一个名为ecosystem.config.js的文件。

    然后,执行以下操作:

    module.exports = {
      apps : [{
        name   : 'myapp', // the name of your app
        cwd    : '/path/to/myapp', // the directory from which your app will be launched
        script : '/usr/local/bin/grunt', // the location of grunt on your system
        args   : 'serve' // the grunt command
      }]
    };
    

    然后,只需运行:

    pm2 start ecosystem.config.js
    

    【讨论】:

      【解决方案2】:

      我建议你创建一个ecosystem file 并放置这些配置:

      script: 'grunt'scriptArgs: ['serve']

      【讨论】:

        猜你喜欢
        • 2023-03-10
        • 1970-01-01
        • 1970-01-01
        • 2015-01-13
        • 2014-06-23
        • 2014-09-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多