Problem running express app with pm2 using ecosystem config file

你说的曾经没有我的故事 提交于 2021-01-28 20:23:52

问题


When I run my Node.js express app using node command everything works fine! When using pm2 server./bin/www` my pm2 status is something like this:

And my app works in this situation. Also when I use pm2 start bin "./bin/www" -i 0 my pm2 list shows:

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:

How should I use config file correctly?


回答1:


Maybe you forgot .config.js in your ecosystem filename.

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).

Note that using a Javascript configuration file requires to end the file name with .config.js



来源:https://stackoverflow.com/questions/58250063/problem-running-express-app-with-pm2-using-ecosystem-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!