简体   繁体   English

使用生态系统配置文件使用 pm2 运行 express 应用程序时出现问题

[英]Problem running express app with pm2 using ecosystem config file

When I run my Node.js express app using node command everything works fine!当我使用node命令运行我的 Node.js express 应用程序时,一切正常! When using pm2 server ./bin/www` my pm2 status is something like this:当使用pm2 server ./bin/www` 我的 pm2 状态是这样的:

在此处输入图像描述

And my app works in this situation.我的应用程序在这种情况下工作。 Also when I use pm2 start bin "./bin/www" -i 0 my pm2 list shows:此外,当我使用pm2 start bin "./bin/www" -i 0我的 pm2 pm2 list显示:

在此处输入图像描述

And yet again my app works.我的应用程序再次运行。 But using following config file:但是使用以下配置文件:

module.exports = {
apps: [{
        name: 'cdn',
        script: './bin/www',
        instances: 0,
        exec_mode: 'cluster',
        watch: true,
        env: {
            NODE_ENV: 'production',
            PORT: process.env.PORT || '5555',
             }
       }]
};

the application while listening on the specified port does not work and prints no error messages and my pm2 status is:侦听指定端口时的应用程序不起作用并且不打印任何错误消息,我的 pm2 状态是:

在此处输入图像描述

How should I use config file correctly?我应该如何正确使用配置文件?

Maybe you forgot .config.js in your ecosystem filename.也许您在生态系统文件名中忘记了.config.js

I lost hours of my day looking for the exact same problem yours and a ignored line of pm2 docs alerts me what I forgot (a weird requirement).我浪费了一天的时间来寻找与您完全相同的问题,并且被忽略的 pm2 文档行提醒我我忘记了什么(一个奇怪的要求)。

Note that using a Javascript configuration file requires to end the file name with.config.js请注意,使用 Javascript 配置文件需要以 .config.js 结尾的文件名

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

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