Search code examples
javascriptnode.jsazureexpressazure-web-app-service

Node.js app not working on Azure App Service


I am new to Azure and trying to deploy my first node js app on Azure App Service. I need help i followed some videos and blogs with Mircosft but i don't know why my app is not working i followed every step.

In my azure protal i can see my project but when i open that URL it just load and load you can see from here https://test-azure-app-node.azurewebsites.net/. when i open logs i can see these logs.

Also after loading it shows this error :( Application Error If you are the application administrator, you can access the

index.js:

import express from 'express'

const port = 80;
const app = express();

app.get('/', (req, res) => {
    res.send("Hello World");
})

app.get('/test', (req, res) => {
    res.send("Hello, Azure")
})

app.listen(port, () => {
    console.log("Server Is Running On Port", port)
})
2023-11-04T12:11:09 Welcome, you are now connected to log-streaming service.

Starting Log Tail -n 10 of existing logs ----/home/LogFiles/__lastCheckTime.txt (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/\__lastCheckTime.txt)11/04/2023 12:11:01/home/LogFiles/kudu/trace/5d8620c911f4-ff0d338d-0294-41de-aa40-0539f407d121.txt (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/5d8620c911f4-ff0d338d-0294-41de-aa40-0539f407d121.txt)

2023-11-04T12:11:08 Startup Request, url: /api/logstream/, method: GET, type: request, pid: 87,1,7, ScmType: None, SCM_DO_BUILD_DURING_DEPLOYMENT: true/home/LogFiles/kudu/trace/efb0ffaae9f5-2e38a9e3-146d-472e-b1e0-577cf788e916.txt (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/efb0ffaae9f5-2e38a9e3-146d-472e-b1e0-577cf788e916.txt)

2023-11-04T10:47:34 Startup Request, url: /api/zipdeploy?author=ms-azuretools-vscode&deployer=ms-azuretools-vscode&isAsync=true&trackDeploymentId=true, method: POST, type: request, pid: 86,1,14, ScmType: None, SCM_DO_BUILD_DURING_DEPLOYMENT: true/home/LogFiles/kudu/trace/efb0ffaae9f5-3a2aa2e0-6a23-478e-9d66-a0b5fcada6f1.txt (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/kudu/trace/efb0ffaae9f5-3a2aa2e0-6a23-478e-9d66-a0b5fcada6f1.txt)

2023-11-04T10:52:19 Outgoing response, type: response, statusCode: 404, statusText: NotFound

/home/LogFiles/2023_11_04_10-30-8-107_default_docker.log (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/2023_11_04_10-30-8-107_default_docker.log)/home/LogFiles/2023_11_04_10-30-8-107_docker.log (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/2023_11_04_10-30-8-107_docker.log)

2023-11-04T12:08:40.147Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 30.4170664 sec

2023-11-04T12:08:55.292Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 45.5615917 sec

2023-11-04T12:09:10.891Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 61.1614305 sec

2023-11-04T12:09:28.400Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 78.6696169 sec

2023-11-04T12:09:43.516Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 93.7857253 sec

2023-11-04T12:09:58.622Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 108.891784 sec

2023-11-04T12:10:13.752Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 124.0219563 sec

2023-11-04T12:10:29.912Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 140.182153 sec

2023-11-04T12:10:45.016Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 155.2862329 sec

2023-11-04T12:11:00.116Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_ce91ac8a. Elapsed time = 170.3854777 sec/home/LogFiles/2023_11_04_10-30-8-108_default_docker.log (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/2023_11_04_10-30-8-108_default_docker.log)

2023-11-04T11:55:36.000783266Z npm info using npm@9.6.4

2023-11-04T11:55:36.001987940Z npm info using node@v18.17.1

2023-11-04T11:55:36.067716235Z

2023-11-04T11:55:36.067759637Z > app@1.0.0 start

2023-11-04T11:55:36.067768438Z > node index.js

2023-11-04T11:55:36.067773738Z

2023-11-04T11:55:36.596291661Z Server Is Running On Port 3000

2023-11-04T11:55:36.779423492Z npm http fetch GET 200 https://registry.npmjs.org/npm 730ms (cache updated)

2023-11-04T11:55:36.846290656Z npm http fetch GET 200 https://registry.npmjs.org/npm 806ms (cache updated)

/home/LogFiles/2023_11_04_10-30-8-108_docker.log (https://test-azure-app-node.scm.azurewebsites.net/api/vfs/LogFiles/2023_11_04_10-30-8-108_docker.log)

2023-11-04T11:57:39.580Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 127.0055714 sec

2023-11-04T11:57:54.688Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 142.1134705 sec

2023-11-04T11:58:11.276Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 158.7012306 sec

2023-11-04T11:58:26.396Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 173.8216572 sec

2023-11-04T11:58:41.529Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 188.9545469 sec

2023-11-04T11:58:56.701Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 204.1264754 sec

2023-11-04T11:59:11.820Z INFO - Waiting for response to warmup request for container test-azure-app-node_0_34624557. Elapsed time = 219.2457876 sec

2023-11-04T11:59:22.924Z ERROR - Container test-azure-app-node_0_34624557 for site test-azure-app-node did not start within expected time limit. Elapsed time = 230.3494381 sec

Solution

  • I have added port 8080 in the code and can deploy it to the Azure web app and see the output.

    Code :

    const express = require('express');
    
    const port = process.env.PORT || 8080; 
    const app = express();
    
    app.get('/', (req, res) => {
      res.send("Hello World");
    });
    
    app.get('/test', (req, res) => {
      res.send("Hello, Azure");
    });
    
    app.listen(port, () => {
      console.log("Server Is Running On Port", port);
    });
    

    package.json :

    {
        "name": "my-node-app",
        "version": "1.0.0",
        "description": "A simple Node.js app",
        "main": "src/index.js",
        "scripts": {
          "start": "node src/index.js"
        },
        "dependencies": {
          "express": "^4.17.1"
        }
      }
    

    Output :

    It runs successfully as below,

    enter image description here

    I got the below output with port 8080 in the browser.

    enter image description here

    enter image description here

    The above code deployed successfully to the Azure web app as below. Then, I click on Browse Website to see the output in the browser.

    enter image description here

    (OR)

    Azure Portal :

    Click on the Browse button in the Azure web app to check the deployment output as below:

    enter image description here

    Browse Output :

    enter image description here

    enter image description here