Error uploading node.js project on azure web app through Github CI/CD

I am uploading my node.js code on Azure web app. After a lot of try, I was able to successfully do it. I am building my code on Visual Studio and pushing to Github and using CI/CD connected to Azure web app. Recently, I connected my code to Azure MySQL server and after that, I have started getting error. I found in the logs that port 8080 is not working. Here’s a snippet of the error:

[DATE] ERROR - Container [CONTAINER_ID] for site [SITE_NAME] has exited, failing site start

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

[DATE] INFO  - Stopping site [SITE_NAME] because it failed during startup.

[DATE] Error details:

  code: 'MODULE_NOT_FOUND',

  requireStack: [ '/home/site/wwwroot/node_modules/express/lib/router/index.js', '/home/site/wwwroot/node_modules/express/lib/application.js', '/home/site/wwwroot/node_modules/express/lib/express.js', '/home/site/wwwroot/node_modules/express/index.js', '/home/site/wwwroot/server.js'

  ]

[DATE] INFO  - Starting container for site

[DATE] INFO  - docker run -d --expose=8080 --name [CONTAINER_NAME] [ENVIRONMENT_VARIABLES] appsvc/node:20-lts_[VERSION] node server.js

[DATE] INFO  - Initiating warmup request to container [CONTAINER_ID] for site [SITE_NAME]

[DATE] ERROR - Container [CONTAINER_ID] for site [SITE_NAME] has exited, failing site start

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

[DATE] INFO  - Stopping site [SITE_NAME] because it failed during startup.

I am not using Docker. I am various measures to do it. Here’s a screenshot of my Web app config. I have added port as 8080:

Here’s my Github workflow:

name: Build and deploy Node.js app to Azure Web App

on:

  push:

    branches:

      - main

  workflow_dispatch:

jobs:

  build-and-deploy:

    runs-on: ubuntu-latest

    steps:

    - uses: actions/checkout@v2

    - name: Set up Node.js version

      uses: actions/setup-node@v1

      with:

        node-version: '20.15.1'

    - name: Create .npmrc file

      run: echo "engine-strict=false" > .npmrc

    - name: Install server dependencies

      run: npm ci

    - name: Build client

      run: |

        cd client

        npm ci

        npm run build

        cd ..

    - name: Create deployment package

      run: |

        zip -r deploy.zip . -x "*.git*" "node_modules/*" "client/node_modules/*" "client/src/*" "client/public/*"

    - name: 'Deploy to Azure Web App'

      uses: azure/webapps-deploy@v2

      with:

        app-name: 'job-search'

        publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}

        package: ./deploy.zip

    - name: Print server.js content

      run: |

        echo "Contents of server.js:"

        cat server.js

    - name: Print Node.js version

      run: node --version

Here’s my server.js:

console.log('Starting server.js');

console.log('Environment variables:', {

  NODE_ENV: process.env.NODE_ENV,

  PORT: process.env.PORT,

  DB_HOST: process.env.DB_HOST,

  DB_USER: process.env.DB_USER,

  DB_NAME: process.env.DB_NAME

  // Don't log DB_PASSWORD

});

process.on('uncaughtException', (err) => {

  console.error('Uncaught Exception:', err);

});

const express = require('express');

const cors = require('cors');

const cron = require('node-cron');

const path = require('path');

const { initializeDatabase } = require(path.join(__dirname, 'server', 'database'));

const { fetchAllJobs, searchJobs, getJobCategories, getCategoryCount, getTotalJobCount } = require(path.path.join(__dirname, 'server', 'jobLogic'));

const app = express();

const port = process.env.PORT || 8080;

// Middleware

app.use(cors());

app.use(express.json());

// Serve static files from the React app

app.use(express.static(path.join(__dirname, 'client/build')));

app.get('/health', (req, res) => {

  res.status(200).send('OK');

});

app.get('*', (req, res) => {

  res.sendFile(path.join(__dirname, 'client/build', 'index.html'));

});

// Error handling middleware

app.use((err, req, res, next) => {

  console.error(err.stack);

  res.status(500).send('Something broke!');

});

app.use((req, res, next) => {

  res.status(404).send("404 - Not Found");

});

// Initialize database and start server

initializeDatabase()

  .then(() => {

    console.log('Database initialized successfully');

    return new Promise((resolve) => {

      const server = app.listen(port, () => {

        console.log(`Server running at http://localhost:${port}`);

        resolve(server);

      });

    });

  })

  .then((server) => {

    console.log('Server started successfully');

    return fetchAllJobs();

  })

  .then(() => {

    console.log('Initial job fetch completed');

  })

  .catch(error => {

    console.error('Error during startup:', error);

    process.exit(1);

  });

// Schedule job fetching (every 6 hours)

//cron.schedule('0 */6 * * *', fetchAllJobs);

This is package.json for server level:

{
  "name": "job-search",
  "version": "0.1.0",
  "main": "server.js",
  "private": true,
  "dependencies": {
    "@testing-library/jest-dom": "^5.17.0",
    "@testing-library/react": "^13.4.0",
    "@testing-library/user-event": "^13.5.0",
    "axios": "^1.7.2",
    "cheerio": "^1.0.0-rc.12",
    "cors": "^2.8.5",
    "csv-parser": "^3.0.0",
    "express": "^4.19.2",
    "lottie-react": "^2.4.0",
    "mysql2": "^3.10.3",
    "node-cache": "^5.1.2",
    "node-cron": "^3.0.3",
    "react": "^18.3.1",
    "react-dom": "^18.3.1",
    "react-scripts": "5.0.1",
    "source-map-support": "^0.5.21",
    "sqlite": "^5.1.1",
    "sqlite3": "^5.1.7",
    "us-state-codes": "^1.1.2",
    "web-vitals": "^2.1.4"
  },
  "scripts": {
    "start": "node server.js",
    "build": "cd client && npm install && npm run build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "dev": "react-scripts start",
    "postinstall": "npm run build"
  },
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest"
    ]
  },
  "browserslist": {
    "production": [
      ">0.2%",
      "not dead",
      "not op_mini all"
    ],
    "development": [
      "last 1 chrome version",
      "last 1 firefox version",
      "last 1 safari version"
    ]
  },
  "engines": {
    "node": "20.15.1"
  },
  "devDependencies": {
    "@babel/core": "^7.24.9",
    "@babel/preset-env": "^7.24.8",
    "babel-loader": "^9.1.3",
    "nodemon-webpack-plugin": "^4.8.2",
    "start-server-webpack-plugin": "^2.2.5",
    "webpack": "^5.93.0",
    "webpack-cli": "^5.1.4",
    "webpack-node-externals": "^3.0.0"
  }
}

I am trying various steps to solve it. But it seems my main issue is with port 8080. Any help with be appreciated.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật