简体   繁体   English

使用 Heroku 和 PM2 部署 Node/Express 服务器

[英]Node/Express server deploy with Heroku and PM2

Attempting to add clustering ability via PM2 and deploy via my Node/Express application.尝试通过 PM2 添加集群功能并通过我的 Node/Express 应用程序进行部署。

I've set up the following command:我已经设置了以下命令:

pm2 start build/server/app.js -i max

The above works fine locally.以上在本地运行良好。 I'm testing the functionality on a staging environment on Heroku via Performance 1X.我正在通过 Performance 1X 在 Heroku 的暂存环境中测试该功能。

Heroku 日志

The above shows the log for the command but attempting 1 instance rather than max .上面显示了命令的日志,但尝试 1 个实例而不是max It shows typical info after successfully running pm2 start however you can see app immediately crashes afterward.它在成功运行 pm2 start 后显示典型信息,但是您可以看到应用程序随后立即崩溃。

Any advice or guidance is appreciated.任何建议或指导表示赞赏。

I ended up using the following documentation: https://pm2.keymetrics.io/docs/integrations/heroku/我最终使用了以下文档: https ://pm2.keymetrics.io/docs/integrations/heroku/

Using a ecosystem.config.js with the following:使用具有以下内容的ecosystem.config.js

module.exports = {
  apps : [
    {
      name: `app-name`,
      script: 'build/server/app.js',
      instances: "max",
      exec_mode: "cluster",
      env: {
        NODE_ENV: "localhost"
      },
      env_development: {
        NODE_ENV: process.env.NODE_ENV
      },
      env_staging: {
        NODE_ENV: process.env.NODE_ENV
      },
      env_production: {
        NODE_ENV: process.env.NODE_ENV
      }
    }
  ],
};

Then the following package.json script handles the deployment per the environment I am looking to deploy eg production:然后以下package.json脚本根据我要部署的环境处理部署,例如生产:

"deploy:cluster:prod": "pm2-runtime start ecosystem.config.js --env production --deep-monitoring",

I got the same error but I fixed it by adding我得到了同样的错误,但我通过添加来修复它

{
"preinstall":"npm I -g pm2",
"start":"pm2-runtime start build/server/app.js -i 1"

}

To my package.json file This is advised for production environment But running到我的 package.json 文件这建议用于生产环境但正在运行

pm2 start build/server/app.js -i max

Is for development purpose是为了开发目的

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM