Reputation: 6668
I have a weird problem I've been scratching my head over. I have an express app which uses pm2 in production mode
cross-env NODE_ENV=production pm2 start ./src/index.js
This works perfectly fine locally. However when I deploy this to Azure App service, the container keeps crashing. I can see the pm2 process starting successfully in the logs but the app then crashes with the following error message
Container didn't respond to pings on port 8080
I have tried setting WEBSITES_PORT
to 8080
and I've tried using process.env.PORT
and hard coding the port to 8080
but nothing has worked.
Does anyone know what might be the cause? I prefer not having to run the application against node in production.
Update I just tried this with supervisor and had the same result. Looks like there is something about process managers that's a problem here, maybe?
Upvotes: 1
Views: 571
Reputation: 5187
Whenever you start your node
server, you should specify the port as given from the environment.
Basic example:
const LOCAL_APP_PORT = 9300;
server.create({ port: process.env.port || LOCAL_APP_PORT })
Note: In order to debug if is pm2
related or not, try for instance to start it simply with node
command.
Update
Based on your last comment. I think the issue might be that pm2
daemonizes itself by default. Could you try to pass the --no-daemon
flag to pm2
command?
Upvotes: 1