I cannot create a Node.JS Web App to be deployed on Azure

0

1

For the past week I've been trying to get Azure to deploy an accessible website with Node.JS. Let me re-count the steps I've done.

1) I go to Visual Studio, and I select the Basic Azure Node.js Express 4 Application.

2) I am given a basic project, and I run the project and open up localhost on my browser to confirm that I can view the basic provided page.

3) I commit all of the code to the Azure Git repo.

4) I create a pipeline on Azure, by using the code on my Azure git repo, allow it to automatically create its own yaml file which looks like this:

# Node.js Express Web App to Linux on Azure
# Build a Node.js Express app and deploy it to Azure as a Linux web app.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master

variables:

  # Azure Resource Manager connection created during pipeline creation
  azureSubscription: '<Censored>'

  # Web app name
  webAppName: 'TheEclipsedLock-Basic-Portfolio-Website-012345'

  # Environment name
  environmentName: 'TheEclipsedLock-Basic-Portfolio-Website-012345'

  # Agent VM image name
  vmImageName: 'ubuntu-latest'

stages:
- stage: Build
  displayName: Build stage
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: $(vmImageName)

    steps:
    - task: NodeTool@0
      inputs:
        versionSpec: '10.x'
      displayName: 'Install Node.js'

    - script: |
        npm install
        npm run build --if-present
        npm run test --if-present
      displayName: 'npm install, build and test'

    - task: ArchiveFiles@2
      displayName: 'Archive files'
      inputs:
        rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
        includeRootFolder: false
        archiveType: zip
        archiveFile: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
        replaceExistingArchive: true

    - upload: $(Build.ArtifactStagingDirectory)/$(Build.BuildId).zip
      artifact: drop

- stage: Deploy
  displayName: Deploy stage
  dependsOn: Build
  condition: succeeded()
  jobs:
  - deployment: Deploy
    displayName: Deploy
    environment: $(environmentName)
    pool: 
      vmImage: $(vmImageName)
    strategy:
      runOnce:
        deploy:
          steps:            
          - task: AzureWebApp@1
            displayName: 'Azure Web App Deploy: TheEclipsedLock-Basic-Portfolio-Website-012345'
            inputs:
              azureSubscription: $(azureSubscription)
              appType: webAppLinux
              appName: $(webAppName)
              runtimeStack: 'NODE|10.10'
              package: $(Pipeline.Workspace)/drop/$(Build.BuildId).zip
              startUpCommand: 'npm run start'

Ok great, all I have to do is wait for the Pipeline to finish, right? Simple, right?

Then I get this:

##[section]Starting: npm install, build and test
==============================================================================
Task         : Command line
Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
Version      : 2.151.2
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
==============================================================================
Generating script.
========================== Starting Command Output ===========================
[command]/bin/bash --noprofile --norc /home/vsts/work/_temp/46ee9b20-5f7d-4b04-a1e3-00bad5c1bb2c.sh
npm WARN saveError ENOENT: no such file or directory, open '/home/vsts/work/package.json'
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN enoent ENOENT: no such file or directory, open '/home/vsts/work/package.json'
npm WARN work No description
npm WARN work No repository field.
npm WARN work No README data
npm WARN work No license field.

audited 22 packages in 0.616s
found 4 vulnerabilities (2 moderate, 2 high)
  run `npm audit fix` to fix them, or `npm audit` for details
npm ERR! path /home/vsts/work/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/vsts/work/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/.npm/_logs/2019-09-06T06_42_26_917Z-debug.log
npm ERR! path /home/vsts/work/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/home/vsts/work/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vsts/.npm/_logs/2019-09-06T06_42_27_284Z-debug.log
##[error]Bash exited with code '254'.
##[section]Finishing: npm install, build and test

I've been digging through google for the past few days, and the various answers I see include to delete the package.json file only to use the npm init command, but if I use npm init, Azure's terminal just stays stuck forever because it's expecting an output and due to the nature of Azure, I cannot simply feed it my own output through its window.

In a separate project in which I developed a small basic website, I created the following yaml file:

# Node.js
# Build a general Node.js project with npm.
# Add steps that analyze code, save build artifacts, deploy, and more:
# https://docs.microsoft.com/azure/devops/pipelines/languages/javascript

trigger:
- master
- development
- feature/*

pool:
  vmImage: 'ubuntu-latest'

steps:
- task: NodeTool@0
  inputs:
    versionSpec: '10.x'
  displayName: 'Install Node.js'

- script: |
    cd AzureWebsite
    npm install
    npm install express
    npm install chai
    npm install mocha
    npm install request
    npm install supertest
    npm install mocha-junit-reporter --save-dev
    npm publish
    cd test
    cd root
    npm install -g mocha
    mocha -R spec server_test.js

- task: ArchiveFiles@2
  displayName: 'Compressing to zip...'
  inputs:
    rootFolderOrFile: '$(System.DefaultWorkingDirectory)'
    includeRootFolder: false
#    archiveType: 'zip'
#    archiveFile: 'web.zip'
#    replaceExistingArchive: true 

- script: |
    ls


- task: CopyFiles@2
  displayName: 'Copying Files...'
  inputs:
    SourceFolder: '$(Build.SourcesDirectory)'
    Contents: |
        **/*
        package.json
    TargetFolder: '$(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publishing Artifacts...'

The purpose of the middle script is to Unit test if certain webpages are accessible. The ArchiveFiles@2 helps for deployment because the publish pipeline complains that it doesn't have any zip files to work off of, so I just use the zip of the working directory. I hope it into the artifact staging directory where it should be published.

And then I plug in that zipped artifact file into the release pipeline and... well you look at that, it finished! Now I can sit back and watch my website-

:( Application Error
If you are the application administrator, you can access the diagnostic resources.
2019-09-06T00:04:02.862036828Z     export NODE_PATH=/node_modules:$NODE_PATH
2019-09-06T00:04:02.862044828Z     export PATH=/node_modules/.bin:$PATH
2019-09-06T00:04:02.862052528Z     if [ -d node_modules ]; then
2019-09-06T00:04:02.870382644Z         mv -f node_modules _del_node_modules || true
2019-09-06T00:04:02.870433146Z         nohup rm -fr _del_node_modules &> /dev/null &
2019-09-06T00:04:02.870561051Z     fi
2019-09-06T00:04:02.870593952Z fi
2019-09-06T00:04:02.879273882Z echo "Done."
2019-09-06T00:04:02.879941807Z if [ -n $injectedAppInsights ]; then
2019-09-06T00:04:02.879960708Z     if [ -f ./oryx-appinsightsloader.js ]; then
2019-09-06T00:04:02.879970308Z         export NODE_OPTIONS='--require ./oryx-appinsightsloader.js '$NODE_OPTIONS
2019-09-06T00:04:02.879978808Z     fi
2019-09-06T00:04:02.881075650Z fi
2019-09-06T00:04:02.881648972Z PATH="$PATH:/home/site/wwwroot" node server.js
2019-09-06T00:04:02.897250264Z Checking if node_modules was compressed...
2019-09-06T00:04:02.897973091Z Done.
2019-09-06T00:04:03.116761493Z internal/modules/cjs/loader.js:583
2019-09-06T00:04:03.116819895Z     throw err;
2019-09-06T00:04:03.116830595Z     ^
2019-09-06T00:04:03.116838996Z 
2019-09-06T00:04:03.116847196Z Error: Cannot find module '/home/site/wwwroot/server.js'
2019-09-06T00:04:03.116855396Z     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-09-06T00:04:03.116863797Z     at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-09-06T00:04:03.116871997Z     at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
2019-09-06T00:04:03.116880197Z     at startup (internal/bootstrap/node.js:282:19)
2019-09-06T00:04:03.116888198Z     at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)

2019-09-06T01:08:39.125915218Z   _____                               
2019-09-06T01:08:39.139973550Z   /  _  \ __________ _________   ____  
2019-09-06T01:08:39.142557948Z  /  /_\  \___   /  |  \_  __ \_/ __ \ 
2019-09-06T01:08:39.142622550Z /    |    \/    /|  |  /|  | \/\  ___/ 
2019-09-06T01:08:39.143569886Z \____|__  /_____ \____/ |__|    \___  >
2019-09-06T01:08:39.143632489Z         \/      \/                  \/ 
2019-09-06T01:08:39.143745093Z A P P   S E R V I C E   O N   L I N U X
2019-09-06T01:08:39.143778294Z 
2019-09-06T01:08:39.143865997Z Documentation: http://aka.ms/webapp-linux
2019-09-06T01:08:39.143898399Z NodeJS quickstart: https://aka.ms/node-qs
2019-09-06T01:08:39.143987702Z NodeJS Version : v10.14.2
2019-09-06T01:08:39.144020103Z 
2019-09-06T01:08:39.740354185Z /opt/startup/init_container.sh: line 32: [: ==: unary operator expected
2019-09-06T01:08:40.004482186Z Oryx Version : 0.2.20190518.2, Commit: 5e1ddd1855bcb53ce686e2124ed6e9603cb0587a
2019-09-06T01:08:40.005254116Z 
2019-09-06T01:08:41.063282880Z Writing output script to '/opt/startup/startup.sh'
2019-09-06T01:08:41.086379955Z Running #!/bin/sh
2019-09-06T01:08:41.086424356Z 
2019-09-06T01:08:41.086434457Z # Enter the source directory to make sure the script runs where the user expects
2019-09-06T01:08:41.086443257Z cd /home/site/wwwroot
2019-09-06T01:08:41.086451357Z 
2019-09-06T01:08:41.086459258Z if [ -f ./oryx-manifest.toml ]; then
2019-09-06T01:08:41.086467358Z     echo "Found 'oryx-manifest.toml'"
2019-09-06T01:08:41.086475358Z     . ./oryx-manifest.toml
2019-09-06T01:08:41.086483058Z fi
2019-09-06T01:08:41.086490559Z 
2019-09-06T01:08:41.086498059Z if [ -z "$PORT" ]; then
2019-09-06T01:08:41.086505959Z         export PORT=8080
2019-09-06T01:08:41.086513960Z fi
2019-09-06T01:08:41.086521460Z 
2019-09-06T01:08:41.086528960Z echo "Checking if node_modules was compressed..."
2019-09-06T01:08:41.086536960Z case $compressedNodeModulesFile in 
2019-09-06T01:08:41.086544761Z     *".zip")
2019-09-06T01:08:41.086552461Z         echo "Found zip-based node_modules."
2019-09-06T01:08:41.086560161Z         extractionCommand="unzip -q $compressedNodeModulesFile -d /node_modules"
2019-09-06T01:08:41.086568162Z         ;;
2019-09-06T01:08:41.086575762Z     *".tar.gz")
2019-09-06T01:08:41.086583562Z         echo "Found tar.gz based node_modules."
2019-09-06T01:08:41.086591463Z         extractionCommand="tar -xzf $compressedNodeModulesFile -C /node_modules"
2019-09-06T01:08:41.086599363Z          ;;
2019-09-06T01:08:41.086617964Z esac
2019-09-06T01:08:41.086626464Z if [ ! -z "$extractionCommand" ]; then
2019-09-06T01:08:41.086634464Z     echo "Removing existing modules directory..."
2019-09-06T01:08:41.086642464Z     rm -fr /node_modules
2019-09-06T01:08:41.086650065Z     mkdir -p /node_modules
2019-09-06T01:08:41.086657665Z     echo "Extracting modules..."
2019-09-06T01:08:41.086665365Z     $extractionCommand
2019-09-06T01:08:41.086673066Z     export NODE_PATH=/node_modules:$NODE_PATH
2019-09-06T01:08:41.086680766Z     export PATH=/node_modules/.bin:$PATH
2019-09-06T01:08:41.086688366Z     if [ -d node_modules ]; then
2019-09-06T01:08:41.090326604Z         mv -f node_modules _del_node_modules || true
2019-09-06T01:08:41.090348105Z         nohup rm -fr _del_node_modules &> /dev/null &
2019-09-06T01:08:41.097109361Z     fi
2019-09-06T01:08:41.097405672Z fi
2019-09-06T01:08:41.097423073Z echo "Done."
2019-09-06T01:08:41.097694483Z if [ -n $injectedAppInsights ]; then
2019-09-06T01:08:41.097710284Z     if [ -f ./oryx-appinsightsloader.js ]; then
2019-09-06T01:08:41.097983994Z         export NODE_OPTIONS='--require ./oryx-appinsightsloader.js '$NODE_OPTIONS
2019-09-06T01:08:41.098000295Z     fi
2019-09-06T01:08:41.099117237Z fi
2019-09-06T01:08:41.099135338Z PATH="$PATH:/home/site/wwwroot" node server.js
2019-09-06T01:08:41.116457593Z Checking if node_modules was compressed...
2019-09-06T01:08:41.117112918Z Done.
2019-09-06T01:08:41.497851236Z internal/modules/cjs/loader.js:583
2019-09-06T01:08:41.497907838Z     throw err;
2019-09-06T01:08:41.497918538Z     ^
2019-09-06T01:08:41.497927039Z 
2019-09-06T01:08:41.497935339Z Error: Cannot find module '/home/site/wwwroot/server.js'
2019-09-06T01:08:41.497943739Z     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:581:15)
2019-09-06T01:08:41.497952239Z     at Function.Module._load (internal/modules/cjs/loader.js:507:25)
2019-09-06T01:08:41.497960640Z     at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
2019-09-06T01:08:41.497968940Z     at startup (internal/bootstrap/node.js:282:19)
2019-09-06T01:08:41.497977140Z     at bootstrapNodeJSCore (internal/bootstrap/node.js:743:3)
2019-09-06 00:02:46.272 INFO  - Starting container for site
2019-09-06 00:02:46.272 INFO  - docker run -d -p 43591:8080 --name theeclipsedlock-portfolio-website-12345_0 -e WEBSITE_NODE_DEFAULT_VERSION=6.9.1 -e APPSETTING_WEBSITE_NODE_DEFAULT_VERSION=6.9.1 -e WEBSITE_SITE_NAME=TheEclipsedLock-Portfolio-Website-12345 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=theeclipsedlock-portfolio-website-12345.azurewebsites.net -e WEBSITE_INSTANCE_ID=366ef1906eda232dd4fa18f32e0793800c765d26b4da9643746011451b789a58 appsvc/node:lts_1905131832 node server.js 

2019-09-06 00:02:46.272 INFO  - Logging is not enabled for this container.
Please use https://aka.ms/linux-diagnostics to enable logging to see container logs here.
2019-09-06 00:02:49.238 INFO  - Initiating warmup request to container theeclipsedlock-portfolio-website-12345_0 for site theeclipsedlock-portfolio-website-12345
2019-09-06 00:02:51.436 ERROR - Container theeclipsedlock-portfolio-website-12345_0 for site theeclipsedlock-portfolio-website-12345 has exited, failing site start
2019-09-06 00:02:51.441 ERROR - Container theeclipsedlock-portfolio-website-12345_0 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2019-09-06 00:04:00.371 INFO  - Starting container for site
2019-09-06 00:04:00.372 INFO  - docker run -d -p 13820:8080 --name theeclipsedlock-portfolio-website-12345_0 -e WEBSITE_NODE_DEFAULT_VERSION=6.9.1 -e APPSETTING_WEBSITE_NODE_DEFAULT_VERSION=6.9.1 -e WEBSITE_SITE_NAME=TheEclipsedLock-Portfolio-Website-12345 -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=theeclipsedlock-portfolio-website-12345.azurewebsites.net -e WEBSITE_INSTANCE_ID=366ef1906eda232dd4fa18f32e0793800c765d26b4da9643746011451b789a58 appsvc/node:lts_1905131832 node server.js 

I'm honestly at my wit's end about this. I have no idea what I can be doing and I can barely find any resources on google because they all imply I'm not using Azure. I know some peers are doing some of the same things as I am and I have followed their advice and watched their own tutorials, but none has resolved the issues I have. I'm praying someone can help point me on the right direction, because I don't know what to do.

Before any comments can arise: Yes, I am new to Node.JS and all I want is to deploy something so that I know it works. I honestly am taking shots in the dark to hopefully stumble onto a configuration that works online even though through localhost it works fine. No, I cannot switch to something other than Node.JS because I've already poured so much time in the past few days trying to get something minimally basic to be deployed.

Thank you for taking the time to read this.

TheEclipsedLock

Posted 2019-09-06T07:28:59.183

Reputation: 1

No answers