English 中文(简体)
PM2: app can’t be reached (ERR_CONNECTION_REFUSED)
原标题:

I have a working Express.js-based app running on Node.js.
Now, I want to wrap it up with pm2. To do that, I ve defined ecosystem.json:

{
    "apps": [
        {
            "env": {
                "NODE_ENV": "development",
                "PORT": "3000"
            },
            "env_production": {
                "NODE_ENV": "production"
            },
            "exec_mode": "cluster",
            "instances": 0,
            "name": "myapp",
            "node_args": [
                "--experimental-json-modules",
                "--gc_interval=100",
                "--max_old_space_size=512",
                "--optimize_for_size"
            ],
            "script": "./src/server/bin/www.mjs",
            "watch": true
        }
    ]
}

In package.json, I ve specified a scripts-section:

"scripts": {
    "start": "pm2 start ecosystem.json"
},

In the IDE, I ve configured an npm script run configuration:

npm run

Now, when I click, pm2 is started and shows a correct running processes summary:

App [myapp] launched (4 instances)

However, when I try to open an app in a browser (127.0.0.1:3000 or localhost:3000), I get ERR_CONNECTION_REFUSED, this site can’t be reached.

It looks like, the app doesn t listen for the port 3000 anymore.
How can I reach my app running in pm2?

P.S. Based on Nodejs + expressjs - pm2 and forever don t work?, I ve checked, I run "script": "./src/server/bin/www.mjs", so I assume, pm2 gets the proper path to the bin/www.mjs.

最佳回答

After exploring the case more detailed, I get ERR_UNSUPPORTED_ESM_URL_SCHEME in the console. The root of the issue is on a side of PM2. The problem is that currently "exec_mode": "cluster" doesn t work, while "exec_mode": "fork" can be used without any issue.

For some reason, this issue has been closed as solved, while in fact it seems like the fix has not been yet released.

问题回答

I also had ERR_CONNECTION_REFUSED.

I use PM2 to run my app and randomly it stopped working after I upgraded from ephemeral to static IP for my GCP instance. I checked the logs and nothing was there. I uninstalled and re-installed but it still didn t work. In the end, I just had to restart my server to get it to work again.





相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签