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:
Now, when I click, pm2 is started and shows a correct running processes summary:
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
.