"I am deploying a Node.js application using PM2 on an Azure App Service. The application appears to start successfully, but it fails the HTTP health check on port 8080, and the site does not start."
"The application should respond to HTTP pings on port 8080, allowing the App Service to start successfully."
"I am deploying a Node.js application using PM2 on an Azure App Service. The application appears to start successfully, but it fails the HTTP health check on port 8080, and the site does not start."
"The application should respond to HTTP pings on port 8080, allowing the App Service to start successfully."
I created simple Nodejs app with PM2 deployed to the Azure App service.
Even I got the same error when hardcoded the port value in the server.js and ecosystem.config.js.
Azure App Service expects the application to listen on the port specified by the PORT environment variable
.
I define the port
value as below
const port = process.env.PORT || 8080;
server.js:
const express = require('express');
const app = express();
const port = process.env.PORT || 8080;
app.get('/', (req, res) => {
res.send('Hello, World! Application is running.');
});
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});
ecosystem.config.js:
module.exports = {
apps: [
{
name: "nodejs-app",
script: "./server.js",
env: {
PORT: 8080
},
env_production: {
NODE_ENV: "production",
PORT: process.env.PORT
}
}
]
};
After successfully deploying the application, I set the following startup command in Azure Web App under Configuration -> Startup Command.
pm2 start ecosystem.config.js --no-daemon
Azure Web App Output: