Deploying a Node.JS application to Azure Web App Service

in Cloud & Serverless


If you deployed your Node.JS app to Azure and you can't get it to run, a common gotcha is the port number your app is listening on.

When troubleshooting, you may be reading that Azure allows incoming connections only to ports 80 and 443. So you make your app listen to 80 or 443, but it still doesn't work. Additionally, in the Log Stream you may be seeing things like

INFO - docker run -d --expose=8080 --name myapp (…)

ERROR - Container myapp didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.

Stackoverflow answers like here https://stackoverflow.com/questions/55688600/azure-web-app-on-linux-error-container-didnt-respond-to-http-pings-on-port or https://stackoverflow.com/questions/66196997/azure-deployment-failure-container-didnt-respond-to-http-pings-on-port-8080 suggesing you set the WEBSITES_PORT environment variable in application settings mislead and do not help.

So where does the 8080 come from if we explicitly set 80 or 443? And why did const port = process.env.port || 8080 indeed solve the problem for this guy? The confusion arises from how Azure App Service for containers handles internal vs. external ports.

  • Internal Port (Container Port): This is the port on which your application is expected to listen inside the container. In Azure App Service for containers, it often defaults to port 8080. This internal port does not need to be publicly accessible. Azure pings this internal container port to check if the app is running.
  • External Port (Accessible from Internet): The App Service itself exposes and routes traffic through port 80 or 443 to the internal port (which is often the aforementioned 8080). In other words, Azure App Service will map port 80 or 443 from the external internet to the port your app is running on internally (e.g., 8080).

So the solution is to have your app listen on 8080, while accessing it through myapp.azurewebsites.net:80 or myapp.azurewebsites.net:443. (For HTTPs requests, your app will automatically share the *.azurewebsites.net certificate.)

#node-js #microsoft-azure