PM2: app can’t be reached (ERR_CONNECTION_REFUSED)

Viewed 576

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.

1 Answers

After exploring the case more detailly, in console I get ERR_UNSUPPORTED_ESM_URL_SCHEME. 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.

Related