1
votes

I'm trying to run the simplest of node.js apps on a Azure App Service (Linux) but I'm out of idéas on how to get this running. I've been trying different approaches and nothing seems to work.

I'm simply deploying the app through FTP and putting the files under "wwwroot" but when requesting the url it loads forever and then ends up with a service unavailable response.

When creating the app I choose Linux as platform, runtime node.js 8.11 and deploy through "code" and not docker.

In the logs I can see this:

docker run -d -p 46852:8080 --name [appname] -e WEBSITE_NODE_DEFAULT_VERSION=8.11 -e APPSETTING_WEBSITE_NODE_DEFAULT_VERSION=8.11 -e WEBSITE_SITE_NAME=[appname] -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_INSTANCE_ID=[id] -e HTTP_LOGGING_ENABLED=1 appsvc/node:8.11.2_1805212105

Container [appname] for site [appname] did not start within expected time limit. Elapsed time = 230.4882261 sec

What does this mean, is docker being used somehow even though I setup the app with deploy through "Code" and FTP.

package.json

{
  "name": "foo",
  "version": "1.0.0",
  "description": "x",
  "author": "x",
  "private": true,
  "scripts": {
    "start": "node server.js"
  },
  "dependencies": {
    "express": "^4.16.3"
  }
}

server.js

const express = require('express')
const app = express()

const port = process.env.PORT || 3000
const host = process.env.HOST || '127.0.0.1'

app.get('/', (req, res) => res.send('Hello!'))

app.listen(port, host)

I've also tried ssh into the app and running npm install. I've tried running the app through ssh console node server.js but ends up with the message "Port already in use". I've tried setting the port to 8080 in "application settings" in Azure Portal.

What am I missing here? How do I get the app running?

2

2 Answers

2
votes

In my site, I just did app.listen(process.env.port); - without the host argument. And try doing npm start.

Also check web.config and iisnode.yml which are generated automatically and are both necessary to run Node.

1
votes

First off, it would be good to know how exactly are you creating your application (tools used, steps taken etc.). Overall, the main thing to understand - Azure App Service does not use Node.js by default, i.e. once you provisioned it. To specify that the host will be running Node app, you need to set 'WEBSITE_NODE_DEFAULT_VERSION' parameter (in Application Settings blade in Azure App Service). Once done, you can deploy with any available option (using publish functionality, local git, using Azure DevOps etc.). Here is a good topic to start with. Getting straight to the point:

  • Install Azure CLI
  • Login to Azure (az login)
  • az account show (to see if you're under the right subscription, in case if you have many). Use 'az account set ' to switch if necessary
  • Then, according to this instruction, create a resource group, service plan and the web app. Set Node.js runtime
  • Compress your app (as per instruction, using either Bash or PS)
  • In the App Service, deploy you app (zipped) using Kudu console (Development tools -> Advanced Tools blade, choose Tools -> Zip Push Deploy from the drop down menu)
  • Review the results.