最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

node.js - Nodejs deployment to azure with error Resource Not Found - Stack Overflow

programmeradmin1浏览0评论

I'm deploying a Nodejs application to azure platform using GitHub actions

and apparently my deployment has succeed

but when I click on app URL it gives me application error message

and after I click on diagnostic resources. link it gives me an error Resource Not Found

and also i found this error in log stream Container mongez-api__04d6 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging

this is the script section in my package.json

"scripts": {
"build": "rimraf build && node esbuild.config.mjs",
"start": "node build/index.cjs"
},

and my github action workflow as follow for azure deployment

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

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: 20

      - name: npm install, build, and test
        run: |
          npm install
          npm run build --if-present
          npm run test --if-present

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'dev'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: node-app

      - name: Unzip artifact for deployment
        run: unzip release.zip
      
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'mongez-api'
          slot-name: 'dev'
          package: .
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2AC3E6F38101424C8DEE01C88E4C81E8 }}

I'm deploying a Nodejs application to azure platform using GitHub actions

and apparently my deployment has succeed

but when I click on app URL it gives me application error message

and after I click on diagnostic resources. link it gives me an error Resource Not Found

and also i found this error in log stream Container mongez-api__04d6 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging

this is the script section in my package.json

"scripts": {
"build": "rimraf build && node esbuild.config.mjs",
"start": "node build/index.cjs"
},

and my github action workflow as follow for azure deployment

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

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v4

      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: 20

      - name: npm install, build, and test
        run: |
          npm install
          npm run build --if-present
          npm run test --if-present

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: release.zip

  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'dev'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: node-app

      - name: Unzip artifact for deployment
        run: unzip release.zip
      
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'mongez-api'
          slot-name: 'dev'
          package: .
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_2AC3E6F38101424C8DEE01C88E4C81E8 }}
Share Improve this question edited Jan 20 at 12:49 Ahmed Abdelrahman asked Jan 20 at 12:07 Ahmed AbdelrahmanAhmed Abdelrahman 1432 silver badges11 bronze badges 10
  • @Ahhmed Abdelrahman Please share the code that you've tried – Sirra Sneha Commented Jan 20 at 12:16
  • if possible please share your github repo . – Sirra Sneha Commented Jan 20 at 12:19
  • it's a private repo not public but you could tell what exactly you are looking for, and i will provide it immediately – Ahmed Abdelrahman Commented Jan 20 at 12:21
  • please provide your index.cjs , package.json files – Sirra Sneha Commented Jan 20 at 12:30
  • also your github workflow file – Sirra Sneha Commented Jan 20 at 12:30
 |  Show 5 more comments

1 Answer 1

Reset to default 0

I created a sample NodeJS application and successfully deployed it to Azure App Service without any errors.

  • The error you're encountering mainly occurs when the port is hardcoded instead of using process.env.PORT, or when using import instead of require in Node.js.
  • So, make sure you use require method in your main file.
const  express  =  require('express');
  • Use below line to define port in your code
const  port  =  process.env.PORT  ||  8080; 

Complete Index.js:

const  express  =  require('express');
const  app  =  express();
const  port  =  process.env.PORT  ||  8080; 
app.get('/', (req, res) => {
res.send('Hello, Azure!');
});
app.listen(port, () => {
console.log(`Server is running on port ${port}`);
});

Package.json:

{
"name": "nodejs-azure-app",
"version": "1.0.0",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"description": "",
"dependencies": {
"express": "^4.21.2"
}
}

Workflow file:

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

on:
  push:
    branches:
      - main
  workflow_dispatch:
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Set up Node.js version
        uses: actions/setup-node@v3
        with:
          node-version: '20.x'
      - name: npm install, build
        run: |
          npm install
          npm run build --if-present         

      - name: Zip artifact for deployment
        run: zip release.zip ./* -r

      - name: Upload artifact for deployment job
        uses: actions/upload-artifact@v4
        with:
          name: node-app
          path: release.zip
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}
    permissions:
      id-token: write 
    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v4
        with:
          name: node-app
      - name: Unzip artifact for deployment
        run: unzip release.zip     
      - name: Login to Azure
        uses: azure/login@v2
        with:
          client-id: ${{ secrets.AZUREAPPSERVICE_CLIENTID_39943DBF6FB44A18929C65569BB20BA0 }}
          tenant-id: ${{ secrets.AZUREAPPSERVICE_TENANTID_8CBE8FFAA5004910A11CC19BBD09C233 }}
          subscription-id: ${{ secrets.AZUREAPPSERVICE_SUBSCRIPTIONID_304AF3CDAE30452F8C74C060F8BEB3EC }}
      - name: 'Deploy to Azure Web App'
        id: deploy-to-webapp
        uses: azure/webapps-deploy@v3
        with:
          app-name: 'nodesample21jan'
          slot-name: 'Production'
          package: .

I've successfully deployed the app via GitHub actions

Output:

发布评论

评论列表(0)

  1. 暂无评论