admin管理员组

文章数量:1335669

"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."

Share Improve this question asked Nov 20, 2024 at 8:19 gokul dotechgokul dotech 1 5
  • Ensure you define your port as follows: const port = process.env.PORT || 8080; in your code. – Aslesha Kantamsetti Commented Nov 20, 2024 at 8:30
  • If possible, share your code? – Aslesha Kantamsetti Commented Nov 21, 2024 at 7:19
  • Can you connect and solve the issue ? – gokul dotech Commented Nov 21, 2024 at 7:40
  • I Give linkedIn Connection – gokul dotech Commented Nov 21, 2024 at 7:41
  • If you encounter any issues, please reach out here only. – Aslesha Kantamsetti Commented Nov 21, 2024 at 9:02
Add a comment  | 

1 Answer 1

Reset to default 0

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:

本文标签: