【问题标题】:How to use pm2 in grunt with a mean.js setup?如何通过 mean.js 设置在 grunt 中使用 pm2?
【发布时间】:2018-03-06 13:46:39
【问题描述】:

我使用 yo 生成器安装了一个带有 grunt 构建的骨架平均 js 程序来进行缩小和部署。

使用 pm2 部署需要采取哪些步骤?

现在我正在使用 nodemon 来保持我的应用程序处于活动状态,并且我正在使用 digitalocean 控制台流来运行以下命令:

NODE_ENV=production PORT:80 grunt --force

根据我的 gruntfile 执行以下操作:

    concurrent: {
        default: ['nodemon', 'watch'],
        options: {
            logConcurrentOutput: true
        }
    },

....

nodemon: {
            dev: {
                script: 'server.js',
                options: {
                    //nodeArgs: ['--debug'],
                    ext: 'js,html',
                    watch: watchFiles.serverViews.concat(watchFiles.serverJS)
                }
            }
        },

grunt.registerTask('default', ['sass','lint', 'concurrent:default']);

我应该在我的 gruntfile 中添加/更改什么配置以使所有这些都与 pm2 一起工作? (我需要它来集群和负载平衡我的应用程序)。

【问题讨论】:

  • 我仍然不清楚如何以及在我的 gruntfile 中配置什么以使其工作。
  • 我认为最好的方法是构建一个用于生产的 sw 版本,然后在 pm2 中运行 app.js 的构建版本。

标签: node.js pm2


【解决方案1】:

在命令行执行:

$ export NODE_ENV=production

将设置生产环境

$ grunt build

将创建必要的 .min.js 和 min.css

$ pm2 start server.js

将使用 pm2 加载服务器,它是一个包,可确保节点服务器在出错时重新启动并记录。

【讨论】:

    猜你喜欢
    • 2014-09-20
    • 2020-07-12
    • 2017-04-25
    • 2016-01-29
    • 2016-06-15
    • 1970-01-01
    • 2023-03-10
    • 2020-09-30
    • 1970-01-01
    相关资源
    最近更新 更多